Skip to content

Commit

Permalink
[PEP 695] Fix handling of undefined name in generic function annotati…
Browse files Browse the repository at this point in the history
…on (#17338)

This was generating a false positive.

Work on #15238.
  • Loading branch information
JukkaL committed Jun 6, 2024
1 parent 09c48a4 commit 8dd268f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 8dd268f

Please sign in to comment.