Skip to content
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

gh-91621: Fix typing.get_type_hints for collections.abc.Callable #91656

Merged
merged 5 commits into from
May 2, 2022

Conversation

hauntsaninja
Copy link
Contributor

@hauntsaninja hauntsaninja commented Apr 18, 2022

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

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
@hauntsaninja
Copy link
Contributor Author

I think we can skip news since this is just a fix for the unreleased #30900

@AlexWaygood AlexWaygood added type-bug An unexpected behavior, bug, or error topic-typing stdlib Python modules in the Lib dir labels Apr 18, 2022
@AlexWaygood
Copy link
Member

I think we can skip news since this is just a fix for the unreleased #30900

Was #30900 not included in 3.11a7? If it was, then I think this probably does need a short NEWS entry :)

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a 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
Copy link
Member

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).

Copy link
Contributor Author

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

@JelleZijlstra JelleZijlstra self-assigned this May 2, 2022
@JelleZijlstra JelleZijlstra merged commit ebb8b51 into python:main May 2, 2022
@hauntsaninja hauntsaninja deleted the calltyp branch May 2, 2022 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants