Skip to content

Commit

Permalink
[PEP 695] Fix crash on invalid type var reference
Browse files Browse the repository at this point in the history
  • Loading branch information
JukkaL committed Sep 19, 2024
1 parent 4554bd0 commit d7b6513
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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

0 comments on commit d7b6513

Please sign in to comment.