Skip to content

fix: fix function object returned from RPC to be a callable - #160

Open
ryanking13 wants to merge 1 commit into
mainfrom
gyeongjae/rpc-wrapper-call
Open

fix: fix function object returned from RPC to be a callable#160
ryanking13 wants to merge 1 commit into
mainfrom
gyeongjae/rpc-wrapper-call

Conversation

@ryanking13

Copy link
Copy Markdown
Contributor

This fixes some bugs related to RPC calls, that I noticed while checking RPC docs examples.

  1. When RPC call returns a function (closure), it was not interpreted as callable.
  2. calling bool(binding) was failing because the Python class fallbacks to len() call when there is no __bool__ implemented.

@ask-bonk

ask-bonk Bot commented Jul 29, 2026

Copy link
Copy Markdown

The code looks solid. Let me verify one more thing about the __len__ change — whether float values from JS could sneak through (JS numbers are always floats, but Pyodide may convert integer-valued floats to Python int):

The isinstance(length, int) check is correct because:

  • If self._binding is an RPC stub, getattr(self._binding, "length", None) will return a JsProxy method/property (not an int), so the check correctly rejects it.
  • If it's a real array-like with .length, Pyodide converts integer JS numbers to Python int, so the check passes.

The tests are well-structured and cover:

  • Callable RPC stubs (both Python-to-Python and Python-to-JS)
  • bool() on bindings and stubs
  • Chained D1 statements staying as _BindingWrapper (not _RpcStubWrapper)
  • len() still raising TypeError on objects without length
  • list() raising TypeError on non-iterable stubs

The test files import _BindingWrapper and _RpcStubWrapper directly from workers.rpc, which are private names (prefixed with _). This is fine for internal tests.

Everything here looks correct and well-tested. The changes are minimal and focused on the two bugs described in the PR.

LGTM

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant