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

[PEP 695] Fix nested generic classes #17776

Merged
merged 7 commits into from
Sep 18, 2024
Merged

[PEP 695] Fix nested generic classes #17776

merged 7 commits into from
Sep 18, 2024

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Sep 17, 2024

There was confusion about the fullnames of type variables in nested generic classes. A type variable could be defined internally as m.OuterClass.T, but it was sometimes accessed as m.T. The root cause was that the semantic analyzer didn't initialize the attribute that refers to the enclosing class consistently.

Fixes #17596. Fixes #17630.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@svalentin svalentin left a comment

Choose a reason for hiding this comment

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

lgtm! Just wondering if we need to worry about triple nested classes or some other odd cases.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Sep 18, 2024

Just wondering if we need to worry about triple nested classes or some other odd cases.

Multiply nested classes don't work with this PR, since lookup_fully_qualified_or_none doesn't support them. I'm leaving it out since they are probably quite rare, but I'll create a follow-up issue.

@JukkaL JukkaL merged commit f68f76d into master Sep 18, 2024
19 checks passed
@JukkaL JukkaL deleted the generics-nested-class branch September 18, 2024 11:22
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.

[PEP 695] Unexpected var-annotated error [PEP 695] Nested generic class fails to typecheck
2 participants