-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
singledispatch support for type annotations #76408
Comments
With the patch attached to this issue, @singledispatch gains support for passing the type in @register via annotations. This looks more natural and enables more thorough type checking without repeating yourself: @singledispatch
def generic(arg): ...
@generic.register
def _(arg: str): ...
@generic.register
def _(arg: int): ... The previous API is still available for backwards compatibility, as well as stacking, and use with classes (sic, I was surprised to learn it's used that way, too). The patch should be uncontroversial, maybe except for the fact that it's importing the |
Idea looks interesting (like a basic runtime @overload). My expectation is that some changes are necessary in mypy for this to work properly. Another (minor) problem is that this creates a circular dependency functools <-> typing. |
Oops something wrong happened. |
Well, it doesn't since I explicitly import typing inside singledispatch. By the time this import happens, functools is fully imported. This would only be a problem if functools itself tried to use singledispatch with annotations. Not impossible but super unlikely. |
Hello, I believe this could be closed as resolved? Do you think it should be added to the What's New? page for 3.7? |
I leave this up to Łukasz. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: