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 crash on invalid type var reference #17788

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6955,6 +6955,7 @@ def name_not_defined(self, name: str, ctx: Context, namespace: str | None = None
namespace is None
and self.type
and not self.is_func_scope()
and self.incomplete_type_stack
and self.incomplete_type_stack[-1]
and not self.final_iteration
):
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,14 @@ class P[T](Protocol[T]): # E: No arguments expected for "Protocol" base class
class P2[T](Protocol[S]): # E: No arguments expected for "Protocol" base class
pass

[case testPEP695CannotUseTypeVarFromOuterClass]
# mypy: enable-incomplete-feature=NewGenericSyntax
class ClassG[V]:
# This used to crash
class ClassD[T: dict[str, V]]: # E: Name "V" is not defined
...
[builtins fixtures/dict.pyi]

[case testPEP695MixNewAndOldStyleGenerics]
# mypy: enable-incomplete-feature=NewGenericSyntax
from typing import TypeVar
Expand Down
Loading