feat(runtime-sdk): improve DO-related type conversions#113
Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This PR adds create_proxy wrapping for callables at the RPC boundary, wraps DurableObjectStorage with _RPCWrapper for consistent type conversions, and adds comprehensive DO binding tests.
Issues
- Dead code:
LambdaTypecheck is now unreachable — The new early return for callables at line 1003 of_raise_on_disabled_typemeans theLambdaTypebranch on line 1009 can never be reached (lambdas are callable and nottype). TheLambdaTypecheck — and its import on line 20 — should be cleaned up to avoid confusion. Note thattupleandbytearrayin that sameisinstancecheck are still reachable since instances of those types are not callable, so those still need guarding.
Suggested change at packages/runtime-sdk/src/workers/_workers.py line 1009:
# Before:
if isinstance(value, (tuple, bytearray, LambdaType)):
# After:
if isinstance(value, (tuple, bytearray)):And remove the now-unused import from types import LambdaType on line 20.
| return | ||
|
|
||
| if callable(value) and not isinstance(value, type): | ||
| return |
There was a problem hiding this comment.
This new early return for callables makes the LambdaType check on line 1009 dead code — lambdas are callable and not type, so they'll always return here before reaching isinstance(value, (tuple, bytearray, LambdaType)).
Consider removing LambdaType from the tuple on line 1009 (changing it to isinstance(value, (tuple, bytearray))) and dropping the from types import LambdaType import on line 20.
|
Review posted successfully on PR #113. I found one actionable issue: Dead code from The rest of the PR looks solid -- the |
This PR is on top of #112 (the target branch).
In addition to #112, this PR adds a few more type conversion improvements in our SDK to make Durable Object bindings work more seamlessly.
It includes
Wrap Python functions with
create_proxywhen passed to the RPC boundary, so that the function is not garbage collected after the function returns. The FinalizationRegistry will now be responsible to cleaning up the function reference later.Wrap
do.ctx.storagewith RPC wrapper so that type conversions are applied there as well just like other bindings.Added more test cases that covers DO api surfaces.