Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,11 @@ def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
and self.is_alias_expression(o.rvalue)
and not self.is_private_name(lvalue.name)
):
alias_type = (
o.unanalyzed_type if isinstance(get_proper_type(o.type), AnyType) else o.type
)
is_explicit_type_alias = (
o.unanalyzed_type and getattr(o.type, "name", None) == "TypeAlias"
o.unanalyzed_type and getattr(alias_type, "name", None) == "TypeAlias"
)
if is_explicit_type_alias:
self.process_typealias(lvalue, o.rvalue, is_explicit_type_alias=True)
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,17 @@ explicit_alias: TypeAlias = tuple[int, str]
implicit_alias = list[int]


[case testExplicitTypeAliasFromUnanalyzedModule_semanal]
from compat import TypeAlias # type: ignore

explicit_alias: TypeAlias = tuple[int, str]

[out]
from compat import TypeAlias as TypeAlias

explicit_alias: TypeAlias = tuple[int, str]


[case testEllipsisAliasPreserved]

alias = Tuple[int, ...]
Expand Down
Loading