Skip to content

Commit 303f01c

Browse files
committed
fix TypeAlias stubgen
1 parent a3ce6d5 commit 303f01c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

mypy/stubgen.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -920,13 +920,14 @@ def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
920920
continue
921921
if (
922922
isinstance(lvalue, NameExpr)
923-
and not self.is_private_name(lvalue.name)
924-
# it is never an alias with explicit annotation
925-
and not o.unanalyzed_type
926923
and self.is_alias_expression(o.rvalue)
924+
and not self.is_private_name(lvalue.name)
927925
):
928-
self.process_typealias(lvalue, o.rvalue)
929-
continue
926+
is_type_alias = o.unanalyzed_type and getattr(o.type, 'name', None) == 'TypeAlias'
927+
if not o.unanalyzed_type or is_type_alias:
928+
self.process_typealias(lvalue, o.rvalue)
929+
continue
930+
930931
if isinstance(lvalue, (TupleExpr, ListExpr)):
931932
items = lvalue.items
932933
if isinstance(o.unanalyzed_type, TupleType): # type: ignore[misc]

test-data/unit/stubgen.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,15 @@ from typing import TypeVar
15441544
T = TypeVar('T')
15451545
alias = Union[T, List[T]]
15461546

1547+
[case testTypeAlias]
1548+
from typing import TypeAlias
1549+
1550+
alias: TypeAlias = tuple[int, str]
1551+
1552+
[out]
1553+
alias = tuple[int, str]
1554+
1555+
15471556
[case testEllipsisAliasPreserved]
15481557

15491558
alias = Tuple[int, ...]

0 commit comments

Comments
 (0)