-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-91621: Fix typing.get_type_hints for collections.abc.Callable #91656
8000 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
Conversation
This mirrors logic in typing.get_args. The trickiness comes from how we flatten args in collections.abc.Callable, see https://bugs.python.org/issue42195
I think we can skip news since this is just a fix for the unreleased #30900 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Lib/typing.py
Outdated
@@ -350,7 +350,11 @@ def _eval_type(t, globalns, localns, recursive_guard=frozenset()): | |||
ForwardRef(arg) if isinstance(arg, str) else arg | |||
for arg in t.__args__ | |||
) | |||
t = t.__origin__[args] | |||
if (t.__origin__ is collections.abc.Callable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this code pattern appears once in Generic code and once here now. Should we just convert this into one function? Maybe _should_flatten_callable_args()
? Seems abit tiresome to repeat this (and it's also confusing for people who haven't dealt with Callable's args before).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(sorry, missed this comment)
I added a helper function for this
This mirrors logic in typing.get_args. The trickiness comes from how we
flatten args in collections.abc.Callable, see
https://bugs.python.org/issue42195
#91621