-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
Fix ClassVar as string fails when getting type hints #6824
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d13c741
Declaring a ClassVar with a type as a string shouldn't fail at runtim…
nnja b8f0472
Address comments from PR. Add additional unit test to test nested Cla…
nnja 79bfabb
Add back a test that was accidentally removed
nnja 5eb9b73
Add NEWS entry
nnja a053fcd
Update 2018-05-15-18-02-03.bpo-0.pj2Mbb.rst
ambv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix failure in `typing.get_type_hints()` when ClassVar was provided as a string forward reference. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 for not having time to review this earlier, this all looks good except for the meaning is exactly the opposite to what I expected :-) There are two options:
is_argumenttois_not_argumenteverywhere (arguably ugly)TruewithFalseand vice versa, and update the corresponding checks@nnja @ambv Will any of you have time to make a PR?
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.
@ilevkivskyi cc/ @ambv Yes, I'll have time tomorrow evening on my flight home.
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.
Ivan, I don't think the meaning is reversed? As I understand it:
If you still want to make a change to this, I would prefer renaming to
is_annotationwhich signifies that we're talking about an entire annotations.Uh oh!
There was an error while loading. Please reload this page.
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.
Renaming to
is_annotationis a possible option, but IMO is still less clear thanis_argumentwith reversed value, since the latter makes simple distinction between these two cases:List['int'], here'int'appears as a type argument in another type'int'here'int'appears just as a typeIn the first case the rules are stricter, e.g.
ClassVarcan't appear as a type argument.In view of this, the ideal option would be to both rename it to
is_type_argumentand reverseFalsetoTrue, but I don't want to ask for too much :-) I will be happy with either option if there will be a short comment explaining whatis_argument/is_annotation/is_type_argumentmeans.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.
Is the term "type argument" used anywhere in typing? I only heard of them being called "generics".
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.
OK, cool, in this case you're right, let's just reverse True with False and vice versa.
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.
@ambv @ilevkivskyi Should I open a new PR for these changes? What's the needed course of action for the backport? #6912
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, please make a PR against master branch. Also it makes sense to do this ASAP, since 3.7rc1 is out in one day.
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.
@ilevkivskyi 👍I can work on this tonight. Will you be available to review?
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.
@ilevkivskyi Done! The updated PR is #7039. Please let me know how it looks.