Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d5c8177
Change assertion to conditional check for tuple type
hyperkai Jan 29, 2026
ad423fd
Add test case for unpacking TypeAlias with TypeVarTuple
hyperkai Jan 29, 2026
f92844f
Fix type alias unpacking syntax errors in tests
hyperkai Jan 29, 2026
bc3db3d
Improve error messages for type alias unpacking
hyperkai Jan 29, 2026
d24ccff
Update check-type-aliases.test with new cases
hyperkai Jan 29, 2026
cb768f6
Fix unpacking errors in type alias tests
hyperkai Jan 29, 2026
d7b4615
Remove Python version flag from test case
hyperkai Jan 29, 2026
1221422
Rename test case for unpacked tuple to xfail
hyperkai Jan 29, 2026
0c0d582
Clarify unpacked type handling in expandtype.py
hyperkai Jan 29, 2026
2676b24
Fix unpacking errors in TypeAlias tests
hyperkai Jan 30, 2026
1121925
Refactor test case for generic type alias unpacking
hyperkai Jan 30, 2026
40cd52d
Update tests for unpacked type alias syntax
hyperkai Jan 30, 2026
c4fc5e5
Rename test cases for unpacked tuple compatibility
hyperkai Jan 30, 2026
5999e31
Refine error messages in check-type-aliases test
hyperkai Jan 30, 2026
8a3c1d0
Revise error messages in check-type-aliases tests
hyperkai Jan 30, 2026
740cdb1
Fix error messages in check-type-aliases test
hyperkai Jan 30, 2026
57535da
Fix type alias unpacking syntax in tests
hyperkai Jan 30, 2026
d4f0e67
Fix unpacking error in TypeAlias test cases
hyperkai Jan 30, 2026
08235af
Clarify unpacking expectations in type alias tests
hyperkai Jan 30, 2026
d66d09d
Fix grammar in comments for type alias tests
hyperkai Jan 30, 2026
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
4 changes: 3 additions & 1 deletion mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,9 @@ def visit_tuple_type(self, t: TupleType) -> Type:
if isinstance(item, UnpackType):
unpacked = get_proper_type(item.type)
if isinstance(unpacked, Instance):
assert unpacked.type.fullname == "builtins.tuple"
# expand_type() may be called during semantic analysis, before invalid unpacks are fixed.
if unpacked.type.fullname != "builtins.tuple":
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment above this line explaining that expand_type() may be called during semantic analysis, before invalid unpacks are fixed.

return t.partial_fallback.accept(self)
if t.partial_fallback.type.fullname != "builtins.tuple":
# If it is a subtype (like named tuple) we need to preserve it,
# this essentially mimics the logic in tuple_fallback().
Expand Down
30 changes: 30 additions & 0 deletions test-data/unit/check-type-aliases.test
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,36 @@ Ta2 = TypeAliasType("Ta2", None, type_params=(Unpack[Ts],)) # E: Free type vari

[builtins fixtures/tuple.pyi]

[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple]
# flags: --python-version 3.11
from typing_extensions import TypeAlias
from typing import TypeVarTuple, Unpack

Ts = TypeVarTuple('Ts')
TA: TypeAlias = tuple[Unpack[Ts]]

# Only "Test suite with py310-ubuntu, mypyc-compiled" expects: Invalid syntax; you likely need to run mypy using Python 3.11 or newer
# The other tests expect: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple)
# v1: TA[*list[int]]

v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple)
[builtins fixtures/tuple.pyi]

[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple310]
# flags: --python-version 3.10
from typing_extensions import TypeAlias
from typing import TypeVarTuple, Unpack

Ts = TypeVarTuple('Ts')
TA: TypeAlias = tuple[Unpack[Ts]]

# Only "Test suite with py310-ubuntu, mypyc-compiled" expects: Invalid syntax
# The other tests expect: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple)
# v1: TA[*list[int]]

v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple)
[builtins fixtures/tuple.pyi]

[case testAliasInstanceNameClash]
from lib import func
class A: ...
Expand Down