Fix run and rpc type annotations and run with function pointer #223
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The type annotations of
run
andrpc
had regressed to return typeHandle[Generator[Any, Any, T] | T
as opposed to just typeT
.This PR fixes this and adds more robust "tests" (implemented as unit tests, checked by pyright) to help mitigate regressions in the future. In addition we are now wrapping the underlying function using
functools.update_wrapper
and binding the identity of theFunction
instance to the function itself.Note:
Ideally, run and rpc would not require special type annotations to work with
Function
(since this class implements the__call__
method and is therefore callable). As best I can tell this is required because the python type system lacks conditional types, therefore the__call__
method is implemented as:Which is not equivalent to
Generator[Any, Any, R]
andR
respectively and likely the reason for the regression. If ever python adds conditional types, or we figure out a better way to implementFunction
we can likely remove these annotations (and switch Function run/rpc to useself._func
which preserves type information) in the future.