-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Support GenericAlias in typing #84576
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
Comments
Currently typing functions get_origin(), get_args() and get_type_hints() do not support GenericAlias. >>> from typing import *
>>> get_origin(List[int])
<class 'list'>
>>> get_origin(list[int])
>>> get_args(List[int])
(<class 'int'>,)
>>> get_args(list[int])
()
>>> def foo(x: List[ForwardRef('X')], y: list[ForwardRef('X')]) -> None: ...
...
>>> class X: ...
...
>>> get_type_hints(foo)
{'x': typing.List[__main__.X], 'y': list[ForwardRef('X')], 'return': <class 'NoneType'>} The proposed PR fixes this. |
@serhiy-storchaka shouldn't list behaves exactly the same as List? (the same question applies to all generics) |
@danielkatzan Looks like an omission in the code for |
@gvanrossum Sure, I would be happy to, but could use a little pointer here note while I can add an explicit if, checking if the tp is actually dict\list etc, and return that instead of None will that be a valid approach? or just masking a deeper issue that might pop up later in a different location? |
This issue was closed 2 years ago, please open a new issue. The fact that |
Changing that would be a breaking change at this point (at least... it would break code that I, personally, have written). |
opened this #95539 |
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: