This PR improves type safety by using ParamSpec for the registration decorators.
mypy now rejects invalid arguments to __call__ or to .dispatch on the decorated function:
@dispatch.function
async def foo(a: int, b: str = "foo") -> list[str]:
return [b] * a
foo(1, "abc") # ok
foo.dispatch(2, b="xyz") # ok
foo("oops") # error: Expected type 'int', got 'str' instead
I added py.typed files to our packages to indicate that type information is available. See https://peps.python.org/pep-0561/ for more information.
I had to make one breaking change, which is that the @dispatch.function and @dispatch.primitive_function decorators no longer accept parameters and return a decorator. These must be used as decorators directly, e.g. @dispatch.function works but @dispatch.function() no longer works as a decorator.
This PR improves type safety by using
ParamSpec
for the registration decorators.mypy now rejects invalid arguments to
__call__
or to.dispatch
on the decorated function:I added
py.typed
files to our packages to indicate that type information is available. See https://peps.python.org/pep-0561/ for more information.I had to make one breaking change, which is that the
@dispatch.function
and@dispatch.primitive_function
decorators no longer accept parameters and return a decorator. These must be used as decorators directly, e.g.@dispatch.function
works but@dispatch.function()
no longer works as a decorator.cc #99