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

bpo-46655: allow stringized TypeAlias with get_type_hints #31156

Merged
merged 3 commits into from
Feb 6, 2022

Conversation

GBeauregard
Copy link
Contributor

@GBeauregard GBeauregard commented Feb 6, 2022

This is a bit weird; it isn't a type, after all. However, _type_check is called as part of stringized annotation resolution so all valid typeforms need a code path to get through it or we will cause errors for get_type_hints calls that may not even be intended to inspect the typeform of issue (e.g. called on a module or class). It also needs to be able to pass through _type_check if you want the typeform to be able to be contained in an Annotated (probably not a concern for TypeAlias).

The most reasonable way I currently know to reach this is if you called get_type_hints on a module with a globally defined TypeAlias (that was stringized). See bpo for additional commentary.

https://bugs.python.org/issue46655

@GBeauregard GBeauregard marked this pull request as ready for review February 6, 2022 08:54
@gvanrossum
Copy link
Member

Do we need backports?

@JelleZijlstra JelleZijlstra added the needs backport to 3.10 only security fixes label Feb 6, 2022
@miss-islington
Copy link
Contributor

Thanks @GBeauregard for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @GBeauregard and @gvanrossum, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 77b025be4a4cd5a3bfc1b1af560cc57e8e956c98 3.10

@JelleZijlstra
Copy link
Member

PEP 613 TypeAlias was new in 3.10, so let's backport to 3.10.

GBeauregard added a commit to GBeauregard/cpython that referenced this pull request Feb 6, 2022
…honGH-31156).

(cherry picked from commit 77b025b)

Co-authored-by: Gregory Beauregard <greg@greg.red>
@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Feb 6, 2022
@bedevere-bot
Copy link

GH-31175 is a backport of this pull request to the 3.10 branch.

@GBeauregard GBeauregard deleted the fix-typealias branch February 6, 2022 23:38
gvanrossum pushed a commit that referenced this pull request Feb 7, 2022
…31156). (#31175)

(cherry picked from commit 77b025b)

Co-authored-by: Gregory Beauregard <greg@greg.red>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants