Skip to content

Commit b915f55

Browse files
committed
Fix forward references in PEP 695 type alias type parameters
1 parent 116b92b commit b915f55

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mypy/semanal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5597,7 +5597,8 @@ def visit_type_alias_stmt(self, s: TypeAliasStmt) -> None:
55975597
else:
55985598
incomplete_target = has_placeholder(res)
55995599

5600-
if self.found_incomplete_ref(tag) or incomplete_target:
5600+
incomplete_tv = any(has_placeholder(tv) for tv in alias_tvars)
5601+
if self.found_incomplete_ref(tag) or incomplete_target or incomplete_tv:
56015602
# Since we have got here, we know this must be a type alias (incomplete refs
56025603
# may appear in nested positions), therefore use becomes_typeinfo=True.
56035604
self.mark_incomplete(s.name.name, s.value, becomes_typeinfo=True)

test-data/unit/check-python312.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,3 +2111,12 @@ if T(x) is str: # E: "TypeAliasType" not callable
21112111
reveal_type(x) # N: Revealed type is "builtins.object"
21122112
[builtins fixtures/tuple.pyi]
21132113
[typing fixtures/typing-full.pyi]
2114+
2115+
[case testPEP695TypeAliasForwardReferenceInUnusedTypeVar]
2116+
# https://discuss.python.org/t/103305
2117+
type Alias1[T: "A"] = int
2118+
type Alias2[T: ("A", int)] = int
2119+
class A: ...
2120+
2121+
x1: Alias1[A] # ok
2122+
x2: Alias2[A] # ok

0 commit comments

Comments
 (0)