Skip to content

Commit dc3103b

Browse files
committed
[PEP 695] Fix handling of undefined name in generic function annotation
Work on #15238.
1 parent 09c48a4 commit dc3103b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

mypy/semanal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ def analyze_func_def(self, defn: FuncDef) -> None:
909909
# Don't store not ready types (including placeholders).
910910
if self.found_incomplete_ref(tag) or has_placeholder(result):
911911
self.defer(defn)
912-
# TODO: pop type args
912+
self.pop_type_args(defn.type_args)
913913
return
914914
assert isinstance(result, ProperType)
915915
if isinstance(result, CallableType):

test-data/unit/check-python312.test

+5
Original file line numberDiff line numberDiff line change
@@ -1489,3 +1489,8 @@ else:
14891489
x: T # E: Name "T" is not defined
14901490
a: A[int]
14911491
reveal_type(a) # N: Revealed type is "builtins.list[builtins.int]"
1492+
1493+
[case testPEP695UndefinedNameInAnnotation]
1494+
# flags: --enable-incomplete-feature=NewGenericSyntax
1495+
def f[T](x: foobar, y: T) -> T: ... # E: Name "foobar" is not defined
1496+
reveal_type(f) # N: Revealed type is "def [T] (x: Any, y: T`-1) -> T`-1"

0 commit comments

Comments
 (0)