Skip to content

Commit b9823f6

Browse files
committed
Fix: Treat bare generic TypeAliasType assignment as variable (Fixes #20308)
1 parent 03b12a1 commit b9823f6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

mypy/semanal.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3493,13 +3493,28 @@ def is_type_ref(self, rv: Expression, bare: bool = False) -> bool:
34933493
else:
34943494
valid_refs = type_constructors
34953495

3496-
if isinstance(rv.node, TypeAlias) or rv.fullname in valid_refs:
3496+
if isinstance(rv.node, TypeAlias):
3497+
# Fix for #20308: Reassignment of a generic TypeAliasType (PEP 695)
3498+
# should be evaluated as a variable assignment, not a type expression.
3499+
# This allows usage like `B = A` where `type A[T] = ...` without
3500+
# triggering "Missing type parameters" error.
3501+
if (
3502+
bare
3503+
and rv.node.python_3_12_type_alias
3504+
and rv.node.alias_tvars
3505+
):
3506+
return False
34973507
return True
3508+
3509+
if rv.fullname in valid_refs:
3510+
return True
3511+
34983512
if isinstance(rv.node, TypeInfo):
34993513
if bare:
35003514
return True
35013515
# Assignment color = Color['RED'] defines a variable, not an alias.
35023516
return not rv.node.is_enum
3517+
35033518
if isinstance(rv.node, Var):
35043519
return rv.node.fullname in NEVER_NAMES
35053520

0 commit comments

Comments
 (0)