-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
Conversation
@ambv @Fidget-Spinner any chance to get a review please? 🙂 |
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 about the delay and thanks for your fix! This looks mostly good to me. I just have a few concerns.
Misc/NEWS.d/next/Library/2021-09-10-21-35-53.bpo-45166.UHipXF.rst
Outdated
Show resolved
Hide resolved
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 |
Thanks for making the requested changes! @Fidget-Spinner: please review the changes made to this pull request. |
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.
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.
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]>
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.
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 |
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.
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.
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.
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! 👍
if not is_class: | ||
invalid_generic_forms += (ClassVar,) | ||
if is_argument: | ||
invalid_generic_forms += (Final,) |
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.
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.
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. Thanks for your patience!
This |
Sorry, @sobolevn and @ambv, I could not cleanly backport this to |
GH-28560 is a backport of this pull request to the 3.10 branch. |
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]>
…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]>
GH-28561 is a backport of this pull request to the 3.9 branch. |
Thanks everyone! 🎉 |
Don't mention it, thank you for the fix! |
…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]>
…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]>
Just a question: will this not be backported to Python 3.8 as well? |
https://bugs.python.org/issue45166