From 8dd268ffd84ccf549b3aa9105dd35766a899b2bd Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 6 Jun 2024 11:43:11 +0100 Subject: [PATCH] [PEP 695] Fix handling of undefined name in generic function annotation (#17338) This was generating a false positive. Work on #15238. --- mypy/semanal.py | 2 +- test-data/unit/check-python312.test | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index 8592a6f05e1f..98184ab41dd7 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -909,7 +909,7 @@ def analyze_func_def(self, defn: FuncDef) -> None: # Don't store not ready types (including placeholders). if self.found_incomplete_ref(tag) or has_placeholder(result): self.defer(defn) - # TODO: pop type args + self.pop_type_args(defn.type_args) return assert isinstance(result, ProperType) if isinstance(result, CallableType): diff --git a/test-data/unit/check-python312.test b/test-data/unit/check-python312.test index 52f77243fd0a..a1c819667087 100644 --- a/test-data/unit/check-python312.test +++ b/test-data/unit/check-python312.test @@ -1489,3 +1489,8 @@ else: x: T # E: Name "T" is not defined a: A[int] reveal_type(a) # N: Revealed type is "builtins.list[builtins.int]" + +[case testPEP695UndefinedNameInAnnotation] +# flags: --enable-incomplete-feature=NewGenericSyntax +def f[T](x: foobar, y: T) -> T: ... # E: Name "foobar" is not defined +reveal_type(f) # N: Revealed type is "def [T] (x: Any, y: T`-1) -> T`-1"