Skip to content

bpo-45166: fixes get_type_hints failure on Final #28279

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

Merged
merged 8 commits into from
Sep 25, 2021
Merged

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Sep 10, 2021

@sobolevn
Copy link
Member Author

@ambv @Fidget-Spinner any chance to get a review please? 🙂

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.

Sorry about the delay and thanks for your fix! This looks mostly good to me. I just have a few concerns.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@sobolevn
Copy link
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@Fidget-Spinner: please review the changes made to this pull request.

Copy link
Contributor

@ambv ambv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good insight about the need for is_class=. I have one change here that we need to make (the __init__ signature) and two suggestions which I think make things clearer.

sobolevn and others added 4 commits September 24, 2021 14:28
Co-authored-by: Łukasz Langa <[email protected]>
Co-authored-by: Łukasz Langa <[email protected]>
Co-authored-by: Łukasz Langa <[email protected]>
Co-authored-by: Łukasz Langa <[email protected]>
@ambv ambv dismissed Fidget-Spinner’s stale review September 24, 2021 11:43

Review changes implemented.

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.

Thanks for your changes. I only have one more nit about adding a docstring :).

@@ -0,0 +1,7 @@
# Tests that top-level ClassVar is not allowed

from __future__ import annotations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, this test fails when you remove this import. So it still allows top-level ClassVar if they aren't strings.

If you'd like to forbid this, you probably need to create another issue/and or PR. This behavior is what typing currently does (since 3.7-3.10). Even if the behavior is wrong, we don't usually backport bugfixes that add extra restrictions (unless it's a security fix) because that usually breaks backwards compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch! I've opened a new issue: https://bugs.python.org/issue45283
I will work on it after this one will be finished.

Thanks! 👍

Comment on lines +167 to +170
if not is_class:
invalid_generic_forms += (ClassVar,)
if is_argument:
invalid_generic_forms += (Final,)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: there's a subtle change in the logic compared to the old code, but it's ok because is_argument defaulted to True in both ForwardRef and _type_check. Which means by default we should always add ClassVar too.

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. Thanks for your patience!

@sobolevn sobolevn closed this Sep 24, 2021
@sobolevn sobolevn reopened this Sep 24, 2021
@sobolevn
Copy link
Member Author

sobolevn commented Sep 24, 2021

This test_asyncio is failing sometimes on Windows, reruning the CI.

@ambv ambv merged commit 784905d into python:main Sep 25, 2021
@miss-islington
Copy link
Contributor

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

@miss-islington
Copy link
Contributor

Sorry, @sobolevn and @ambv, I could not cleanly backport this to 3.9 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 784905dbeff68cf788bbeefe0a675af1af04affc 3.9

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Sep 25, 2021
@bedevere-bot
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 25, 2021
Co-authored-by: Łukasz Langa <[email protected]>
Co-authored-by: Ken Jin <[email protected]>
(cherry picked from commit 784905d)

Co-authored-by: Nikita Sobolev <[email protected]>
ambv pushed a commit to ambv/cpython that referenced this pull request Sep 25, 2021
…28279)

Co-authored-by: Łukasz Langa <[email protected]>
Co-authored-by: Ken Jin <[email protected]>.
(cherry picked from commit 784905d)

Co-authored-by: Nikita Sobolev <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Sep 25, 2021
@bedevere-bot
Copy link

GH-28561 is a backport of this pull request to the 3.9 branch.

@sobolevn
Copy link
Member Author

Thanks everyone! 🎉

@ambv
Copy link
Contributor

ambv commented Sep 25, 2021

Don't mention it, thank you for the fix!

ambv pushed a commit that referenced this pull request Sep 25, 2021
…8560)

Co-authored-by: Łukasz Langa <[email protected]>
Co-authored-by: Ken Jin <[email protected]>
(cherry picked from commit 784905d)

Co-authored-by: Nikita Sobolev <[email protected]>
ambv added a commit that referenced this pull request Sep 25, 2021
…GH-28561)

Co-authored-by: Łukasz Langa <[email protected]>
Co-authored-by: Ken Jin <[email protected]>.
(cherry picked from commit 784905d)

Co-authored-by: Nikita Sobolev <[email protected]>
@pawamoy
Copy link

pawamoy commented Sep 26, 2021

Just a question: will this not be backported to Python 3.8 as well?

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.

7 participants