Repository navigation
Bypass class attribute lookup for PEP 695 typevars - #20292
Merged
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
sterliakov
approved these changes
Nov 24, 2025
sterliakov
left a comment
Collaborator
There was a problem hiding this comment.
Nice one! This part definitely should not use lookup, we are only interested in locals, and (except for one bad corner case) only in the most recent locals entry. Traversing further is only needed when we have
class Foo[T]:
class Bar[T]: # Error here, but typevar is still needed
...
sterliakov
reviewed
Nov 26, 2025
sterliakov
reviewed
Nov 26, 2025
Member
|
@A5rocks I think it makes sense to implement comments by @sterliakov, also there is a little merge conflict, but otherwise this LG. |
A5rocks
force-pushed
the
use-locals-always
branch
from
October 14, 2026 20:49
5feef39 to
896f122
Compare
Collaborator
Author
|
Done! Sorry for the wait. |
ilevkivskyi
approved these changes
Oct 14, 2026
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #20283
This is a bit gross, but I'm not sure how to better do this. The problem is that we look up class attributes before looking at locals, but then put the type vars in a new locals scope. I guess one idea would be to define the typevars at usage time? But this is less of a change.