-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typing for decorators transforming input arguments to new type #7603
Comments
For example, one solution approach would be to use:
which correctly handles |
Yeah, this is an unfortunate shortcoming that is covered in #1317 and maybe others (python/typing#193). We're hoping to improve on this, though the timeframe is somewhat unclear. Currently the best solution is to write a bunch of overloads (for 0-6 arguments, for example), though that won't work for arbitrarily named keyword arguments. |
I see, thanks! |
Please forgive me if this issue is already solved or if it is part of #1317, but I'm not sure this is already covered with the existing issues. I'm trying to find a solution for the following use case:
I have a decorator, which changes functions to accept all arguments inside a
Tuple
. The current solution works and doesn't give any mypy errors, because the type of the decorated functions isand basically looses all typing information.
However, after the decorator is applied, the four last lines should give an error, since the decorated function only accepts tuples now.
Is or will there be a way type decorator so that these cases can be solved? I tried different solutions with generics and overloads, but didn't manage to improve upon
Callable[..., None]
.Or, in other words, I would like to add more typing information to
decorator
to allowmypy
to convert decorated functions fromCallable[[T1, T2, T3], None]
toCallable[[Tuple[T1], Tuple[T2], Tuple[T3]], None]
The text was updated successfully, but these errors were encountered: