dispatchrun / dispatch-py

Python package to develop applications with Dispatch.
https://pypi.org/project/dispatch-py/
Apache License 2.0
54 stars 3 forks source link

The .dispatch method injected by function decorator loses type information #99

Closed achille-roussel closed 6 months ago

achille-roussel commented 6 months ago

The signature of the .dispatch method we add to decorated functions is *args, **kwargs, which says nothing about the types of arguments expected to be received. We know the arguments should be the same as those of the decorated function, but a type checker doesn't.

PEP-0612 introduces the ParamSpec concept, allowing us to express arbitrary function signatures as type annotations.

Maintaining type information is critical to leverage the type-checking capabilities of tools like mypy and Python IDEs. Without it, we create a fertile ground for developers to introduce errors that would prevent them from leveraging Dispatch.

As part of this change, we may have to abandon #43, because ParamSpec was introduced in Python 3.10.

Other challenges may get in the way of addressing this issue:

Strong type checking is much more important than leaner APIs, so if we have to sacrifice some of the syntactic simplicity we have today to acquire stronger type checks, we should do it. If it turns out that we have to introduce breaking changes, let's relabel this issue as such.