Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 6 additions & 5 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,13 +920,14 @@ def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
continue
if (
isinstance(lvalue, NameExpr)
and not self.is_private_name(lvalue.name)
# it is never an alias with explicit annotation
and not o.unanalyzed_type
and self.is_alias_expression(o.rvalue)
and not self.is_private_name(lvalue.name)
):
self.process_typealias(lvalue, o.rvalue)
continue
is_type_alias = o.unanalyzed_type and getattr(o.type, "name", None) == "TypeAlias"
if not o.unanalyzed_type or is_type_alias:
self.process_typealias(lvalue, o.rvalue)
continue

if isinstance(lvalue, (TupleExpr, ListExpr)):
items = lvalue.items
if isinstance(o.unanalyzed_type, TupleType): # type: ignore[misc]
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,15 @@ from typing import TypeVar
T = TypeVar('T')
alias = Union[T, List[T]]

[case testTypeAlias]
from typing import TypeAlias

alias: TypeAlias = tuple[int, str]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
alias: TypeAlias = tuple[int, str]
explicit_alias: TypeAlias = tuple[int, str]
implicit_alias = list[int]

Copy link
Contributor Author

@makridenko makridenko May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this, thank you


[out]
alias = tuple[int, str]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we should skip TypeAlias here. It should be like this, in my opinion:

Suggested change
alias = tuple[int, str]
from typing import TypeAlias
alias: TypeAlias = tuple[int, str]



[case testEllipsisAliasPreserved]

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