From d5c817705eacbfdfd974de566c0f52e6eab7e4c4 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 05:32:55 +0900 Subject: [PATCH 01/28] Change assertion to conditional check for tuple type --- mypy/expandtype.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/expandtype.py b/mypy/expandtype.py index 7f95b2e25320d..81dafc1a6b581 100644 --- a/mypy/expandtype.py +++ b/mypy/expandtype.py @@ -541,7 +541,8 @@ 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" + if unpacked.type.fullname != "builtins.tuple": + 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(). From ad423fd587e23bf3fe6aed470561446ed71e0b9a Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 05:35:56 +0900 Subject: [PATCH 02/28] Add test case for unpacking TypeAlias with TypeVarTuple --- test-data/unit/check-type-aliases.test | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 61eda2bd77747..16615dae45268 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1237,6 +1237,18 @@ Ta2 = TypeAliasType("Ta2", None, type_params=(Unpack[Ts],)) # E: Free type vari [builtins fixtures/tuple.pyi] +[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] +from typing_extensions import TypeAlias +from typing import TypeVarTuple, Unpack + +Ts = TypeVarTuple('Ts') + +TA: TypeAlias = tuple[Unpack[Ts]] + +v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +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: ... From f92844f66e8263a57cbb2373edaa965dd7bdf2c4 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 06:26:29 +0900 Subject: [PATCH 03/28] Fix type alias unpacking syntax errors in tests Updated type alias test cases to reflect syntax changes. --- test-data/unit/check-type-aliases.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 16615dae45268..a1b6583662b68 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1245,8 +1245,8 @@ Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v1: TA[*list[int]] # E: Invalid syntax... +v2: TA[Unpack[list[int]]] # E: Invalid syntax... [builtins fixtures/tuple.pyi] [case testAliasInstanceNameClash] From bc3db3d265b188a074cb7950d87880074309d63e Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 06:49:58 +0900 Subject: [PATCH 04/28] Improve error messages for type alias unpacking Update error messages for invalid syntax in type alias tests. --- test-data/unit/check-type-aliases.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index a1b6583662b68..16615dae45268 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1245,8 +1245,8 @@ Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: Invalid syntax... -v2: TA[Unpack[list[int]]] # E: Invalid syntax... +v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] [case testAliasInstanceNameClash] From d24ccff3e899ff653775312e6e70ac73df467943 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 07:41:51 +0900 Subject: [PATCH 05/28] Update check-type-aliases.test with new cases Add tests for type alias unpacking with lists. --- test-data/unit/check-type-aliases.test | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 16615dae45268..6c7b042548d0e 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1245,8 +1245,16 @@ Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v1: TA[*list[int]] +v2: TA[Unpack[list[int]]] + +[out-python3.10] +main:8: error: Invalid syntax +main:9: error: Invalid syntax + +[out] +main:8: error: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +main:9: error: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] [case testAliasInstanceNameClash] From cb768f6dc0f9c9b3cb535954677f5e93808d8ad3 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 08:09:21 +0900 Subject: [PATCH 06/28] Fix unpacking errors in type alias tests Update type alias tests to reflect unpacking errors for list[int]. --- test-data/unit/check-type-aliases.test | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 6c7b042548d0e..41b9e9b820926 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1238,6 +1238,7 @@ Ta2 = TypeAliasType("Ta2", None, type_params=(Unpack[Ts],)) # E: Free type vari [builtins fixtures/tuple.pyi] [case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] +# flags: --python-version 3.10 from typing_extensions import TypeAlias from typing import TypeVarTuple, Unpack @@ -1245,17 +1246,11 @@ Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] -v2: TA[Unpack[list[int]]] - -[out-python3.10] -main:8: error: Invalid syntax -main:9: error: Invalid syntax +v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -[out] -main:8: error: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -main:9: error: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] +xfail: True [case testAliasInstanceNameClash] from lib import func From d7b46154e6db209c6f23b35cf665061e5749ef84 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 08:31:32 +0900 Subject: [PATCH 07/28] Remove Python version flag from test case --- test-data/unit/check-type-aliases.test | 1 - 1 file changed, 1 deletion(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 41b9e9b820926..02129c01ce1d1 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1238,7 +1238,6 @@ Ta2 = TypeAliasType("Ta2", None, type_params=(Unpack[Ts],)) # E: Free type vari [builtins fixtures/tuple.pyi] [case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] -# flags: --python-version 3.10 from typing_extensions import TypeAlias from typing import TypeVarTuple, Unpack From 1221422c961e9c24dd9d4c95c91c47982adf2188 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 08:56:23 +0900 Subject: [PATCH 08/28] Rename test case for unpacked tuple to xfail --- test-data/unit/check-type-aliases.test | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 02129c01ce1d1..d757632e06dfc 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1237,7 +1237,7 @@ Ta2 = TypeAliasType("Ta2", None, type_params=(Unpack[Ts],)) # E: Free type vari [builtins fixtures/tuple.pyi] -[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] +[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple-xfail] from typing_extensions import TypeAlias from typing import TypeVarTuple, Unpack @@ -1245,11 +1245,10 @@ Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] +# For Python 3.10, error: Invalid syntax v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) - [builtins fixtures/tuple.pyi] -xfail: True [case testAliasInstanceNameClash] from lib import func From 0c0d5821d85d335bd288a3440fcff16ef0f7378a Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 08:58:08 +0900 Subject: [PATCH 09/28] Clarify unpacked type handling in expandtype.py Add comment to clarify behavior during semantic analysis. --- mypy/expandtype.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mypy/expandtype.py b/mypy/expandtype.py index 81dafc1a6b581..5790b717172ac 100644 --- a/mypy/expandtype.py +++ b/mypy/expandtype.py @@ -541,6 +541,7 @@ def visit_tuple_type(self, t: TupleType) -> Type: if isinstance(item, UnpackType): unpacked = get_proper_type(item.type) if isinstance(unpacked, Instance): + # expand_type() may be called during semantic analysis, before invalid unpacks are fixed. if unpacked.type.fullname != "builtins.tuple": return t.partial_fallback.accept(self) if t.partial_fallback.type.fullname != "builtins.tuple": From 2676b2488f04a5f5b307ed9c5dd689898eca3831 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 09:19:24 +0900 Subject: [PATCH 10/28] Fix unpacking errors in TypeAlias tests Updated test cases for TypeAlias unpacking in Python. --- test-data/unit/check-type-aliases.test | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index d757632e06dfc..fe0fef3060a0f 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1246,8 +1246,9 @@ Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] # For Python 3.10, error: Invalid syntax -v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +# For other Python, error: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v1: TA[*list[int]] +v2: TA[Unpack[list[int]]] [builtins fixtures/tuple.pyi] [case testAliasInstanceNameClash] From 112192547ba18200d07612f3e41ee916a5e409a3 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 14:46:10 +0900 Subject: [PATCH 11/28] Refactor test case for generic type alias unpacking Removed xfail marker from test case and updated comments for clarity. --- test-data/unit/check-type-aliases.test | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index fe0fef3060a0f..208333f4fcc17 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1237,7 +1237,7 @@ Ta2 = TypeAliasType("Ta2", None, type_params=(Unpack[Ts],)) # E: Free type vari [builtins fixtures/tuple.pyi] -[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple-xfail] +[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] from typing_extensions import TypeAlias from typing import TypeVarTuple, Unpack @@ -1245,10 +1245,9 @@ Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -# For Python 3.10, error: Invalid syntax -# For other Python, error: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -v1: TA[*list[int]] -v2: TA[Unpack[list[int]]] +v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +# python3.10: Invalid syntax [builtins fixtures/tuple.pyi] [case testAliasInstanceNameClash] From 40cd52d33ff61534cf125fac97ad7c636525e3db Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 15:14:56 +0900 Subject: [PATCH 12/28] Update tests for unpacked type alias syntax Add test cases for unpacked type aliases in Python 3.10 and 3.11 --- test-data/unit/check-type-aliases.test | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 208333f4fcc17..9df4a76506934 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1237,17 +1237,26 @@ Ta2 = TypeAliasType("Ta2", None, type_params=(Unpack[Ts],)) # E: Free type vari [builtins fixtures/tuple.pyi] -[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] +[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple-python311] from typing_extensions import TypeAlias from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') - TA: TypeAlias = tuple[Unpack[Ts]] v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -# python3.10: Invalid syntax +[builtins fixtures/tuple.pyi] + +[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple-python310] +from typing_extensions import TypeAlias +from typing import TypeVarTuple, Unpack + +Ts = TypeVarTuple('Ts') +TA: TypeAlias = tuple[Unpack[Ts]] + +v1: TA[*list[int]] # E: main:7: error: Invalid syntax +v2: TA[Unpack[list[int]]] # E: main:8: error: Invalid syntax [builtins fixtures/tuple.pyi] [case testAliasInstanceNameClash] From c4fc5e560ec78fa20683edf710aa7334612b95ec Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 15:32:30 +0900 Subject: [PATCH 13/28] Rename test cases for unpacked tuple compatibility --- test-data/unit/check-type-aliases.test | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 9df4a76506934..b24656d14952e 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1237,7 +1237,8 @@ Ta2 = TypeAliasType("Ta2", None, type_params=(Unpack[Ts],)) # E: Free type vari [builtins fixtures/tuple.pyi] -[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple-python311] +[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] +# flags: --python-version 3.11 from typing_extensions import TypeAlias from typing import TypeVarTuple, Unpack @@ -1248,7 +1249,8 @@ v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] -[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple-python310] +[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple310] +# flags: --python-version 3.10 from typing_extensions import TypeAlias from typing import TypeVarTuple, Unpack From 5999e316fc98e62be83bf381d12b1b7e2defa370 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 15:52:56 +0900 Subject: [PATCH 14/28] Refine error messages in check-type-aliases test Update error messages for type alias unpacking tests. --- test-data/unit/check-type-aliases.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index b24656d14952e..ee7afddd07964 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1257,8 +1257,8 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: main:7: error: Invalid syntax -v2: TA[Unpack[list[int]]] # E: main:8: error: Invalid syntax +v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] [case testAliasInstanceNameClash] From 8a3c1d0d175f79229a2018bcaa06c14c93d944dc Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 16:15:29 +0900 Subject: [PATCH 15/28] Revise error messages in check-type-aliases tests Update error messages for unpacking list in type alias tests to reflect Python version requirements. --- test-data/unit/check-type-aliases.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index ee7afddd07964..f009728f742a8 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1245,7 +1245,7 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v1: TA[*list[int]] # E: Invalid syntax; you likely need to run mypy using Python 3.11 or newer v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] @@ -1257,7 +1257,7 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v1: TA[*list[int]] # E: Invalid syntax v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] From 740cdb1417b9b07a314c131e5b886e6c463fadcb Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 16:31:03 +0900 Subject: [PATCH 16/28] Fix error messages in check-type-aliases test Updated error messages for unpacking list[int] in type alias tests. --- test-data/unit/check-type-aliases.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index f009728f742a8..ee7afddd07964 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1245,7 +1245,7 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: Invalid syntax; you likely need to run mypy using Python 3.11 or newer +v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] @@ -1257,7 +1257,7 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: Invalid syntax +v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] From 57535dab1791fc8674d424797dca1c116fee0173 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 17:37:02 +0900 Subject: [PATCH 17/28] Fix type alias unpacking syntax in tests Updated type alias test cases to reflect syntax changes in Python 3.11. --- test-data/unit/check-type-aliases.test | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index ee7afddd07964..b440f8e840745 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1245,7 +1245,10 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v1: TA[*list[int]] +# python3.10: Invalid syntax; you likely need to run mypy using Python 3.11 or newer +# E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) + v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] @@ -1257,7 +1260,10 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +v1: TA[*list[int]] +# python3.10: Invalid syntax +# E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) + v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] From d4f0e67bcd77451e034c22cf13580cee43a05b1c Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 17:51:16 +0900 Subject: [PATCH 18/28] Fix unpacking error in TypeAlias test cases Updated test cases to reflect unpacking rules for TypeAlias. --- test-data/unit/check-type-aliases.test | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index b440f8e840745..77b0f8b1a6ad6 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1245,9 +1245,8 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] +v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) # python3.10: Invalid syntax; you likely need to run mypy using Python 3.11 or newer -# E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] @@ -1260,9 +1259,8 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] +v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) # python3.10: Invalid syntax -# E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) [builtins fixtures/tuple.pyi] From 08235af0d7d5704f49d7c690f5e3b38d44425d0d Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 18:19:45 +0900 Subject: [PATCH 19/28] Clarify unpacking expectations in type alias tests Update comments to clarify expectations for unpacking lists in type aliases. --- test-data/unit/check-type-aliases.test | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 77b0f8b1a6ad6..53c93e5b02a0c 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1245,8 +1245,9 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -# python3.10: Invalid syntax; you likely need to run mypy using Python 3.11 or newer +# 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 expects: "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] @@ -1259,8 +1260,9 @@ from typing import TypeVarTuple, Unpack Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] -v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -# python3.10: Invalid syntax +# Only "Test suite with py310-ubuntu, mypyc-compiled" expects: Invalid syntax +# The other tests expects: "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] From d66d09da8cbc1d24f1d3a8b090555c5008c71919 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 30 Jan 2026 18:23:41 +0900 Subject: [PATCH 20/28] Fix grammar in comments for type alias tests --- test-data/unit/check-type-aliases.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 53c93e5b02a0c..e225593312f24 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1246,7 +1246,7 @@ 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 expects: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +# 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) @@ -1261,7 +1261,7 @@ Ts = TypeVarTuple('Ts') TA: TypeAlias = tuple[Unpack[Ts]] # Only "Test suite with py310-ubuntu, mypyc-compiled" expects: Invalid syntax -# The other tests expects: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +# 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) From f921b76eed6fd72c7daf8b398a88d48be7d188c3 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Sun, 1 Feb 2026 16:19:54 +0900 Subject: [PATCH 21/28] Add test cases for TypeAlias and TypeVarTuple --- test-data/unit/check-python311.test | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test-data/unit/check-python311.test b/test-data/unit/check-python311.test index 42bdb72411ecb..a8567d5eeed07 100644 --- a/test-data/unit/check-python311.test +++ b/test-data/unit/check-python311.test @@ -321,3 +321,15 @@ def exc_name() -> None: except* RuntimeError as e: e = fn_exc(e) [builtins fixtures/exception.pyi] + +[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] +from typing_extensions import TypeAlias +from typing import TypeVarTuple, Unpack + +Ts = TypeVarTuple('Ts') +TA: TypeAlias = tuple[Unpack[Ts]] + +# v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) + +v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +[builtins fixtures/tuple.pyi] From a6532437d246508f11560eade106d8149ae9b1f0 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Sun, 1 Feb 2026 16:24:03 +0900 Subject: [PATCH 22/28] Delete unpacking type alias tests for Python versions Remove tests for unpacking type aliases in Python 3.10 and 3.11. --- test-data/unit/check-type-aliases.test | 30 -------------------------- 1 file changed, 30 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index e225593312f24..61eda2bd77747 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1237,36 +1237,6 @@ 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: ... From 3c0287e2a11aa25c5aaba2d3a4d18dde0c973f9e Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Sun, 1 Feb 2026 16:26:39 +0900 Subject: [PATCH 23/28] Add test case for unpacked tuple in TypeAlias --- test-data/unit/check-python310.test | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test-data/unit/check-python310.test b/test-data/unit/check-python310.test index 3abf5673fa667..4f0139c184e3c 100644 --- a/test-data/unit/check-python310.test +++ b/test-data/unit/check-python310.test @@ -2389,6 +2389,18 @@ X = None | C Y = None | D [builtins fixtures/type.pyi] +[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] +from typing_extensions import TypeAlias +from typing import TypeVarTuple, Unpack + +Ts = TypeVarTuple('Ts') +TA: TypeAlias = tuple[Unpack[Ts]] + +# v1: TA[*list[int]] # E: Invalid syntax + +v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +[builtins fixtures/tuple.pyi] + [case testMatchStatementWalrus] class A: a = 1 From b5aa88e1dc12ba5389aa76a59959284f57d2fade Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Sun, 1 Feb 2026 16:41:59 +0900 Subject: [PATCH 24/28] Remove TypeAlias unpacking test cases Removed test cases related to TypeAlias unpacking for tuples. --- test-data/unit/check-python311.test | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test-data/unit/check-python311.test b/test-data/unit/check-python311.test index a8567d5eeed07..42bdb72411ecb 100644 --- a/test-data/unit/check-python311.test +++ b/test-data/unit/check-python311.test @@ -321,15 +321,3 @@ def exc_name() -> None: except* RuntimeError as e: e = fn_exc(e) [builtins fixtures/exception.pyi] - -[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] -from typing_extensions import TypeAlias -from typing import TypeVarTuple, Unpack - -Ts = TypeVarTuple('Ts') -TA: TypeAlias = tuple[Unpack[Ts]] - -# v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) - -v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -[builtins fixtures/tuple.pyi] From f1e2e85dfaa833a0339add5a2fea81f8db0f084c Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Sun, 1 Feb 2026 16:42:58 +0900 Subject: [PATCH 25/28] Delete test case for TypeAlias unpacking Remove test case for unpacked tuple with TypeAlias --- test-data/unit/check-python310.test | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test-data/unit/check-python310.test b/test-data/unit/check-python310.test index 4f0139c184e3c..3abf5673fa667 100644 --- a/test-data/unit/check-python310.test +++ b/test-data/unit/check-python310.test @@ -2389,18 +2389,6 @@ X = None | C Y = None | D [builtins fixtures/type.pyi] -[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] -from typing_extensions import TypeAlias -from typing import TypeVarTuple, Unpack - -Ts = TypeVarTuple('Ts') -TA: TypeAlias = tuple[Unpack[Ts]] - -# v1: TA[*list[int]] # E: Invalid syntax - -v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) -[builtins fixtures/tuple.pyi] - [case testMatchStatementWalrus] class A: a = 1 From 3608ab4d0efd4301dd6e8474dfc6514aea60b663 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Sun, 1 Feb 2026 16:44:56 +0900 Subject: [PATCH 26/28] Add tests for unpacked TypeAlias with TypeVarTuple Add test cases for unpacking TypeAlias with TypeVarTuple in Python 3.10 and 3.11. --- test-data/unit/check-type-aliases.test | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 61eda2bd77747..e225593312f24 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -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: ... From fd82e4fb0acd2e6533650a6432aa21a22791f881 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sun, 1 Feb 2026 11:52:50 +0000 Subject: [PATCH 27/28] Update check-python311.test --- test-data/unit/check-python311.test | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test-data/unit/check-python311.test b/test-data/unit/check-python311.test index 42bdb72411ecb..51b47b6746fdb 100644 --- a/test-data/unit/check-python311.test +++ b/test-data/unit/check-python311.test @@ -321,3 +321,15 @@ def exc_name() -> None: except* RuntimeError as e: e = fn_exc(e) [builtins fixtures/exception.pyi] + +[case testGenericTypeAliasArgOfTypeAliasIsUnpackedTuple] +from typing_extensions import TypeAlias +from typing import TypeVarTuple, Unpack + +Ts = TypeVarTuple('Ts') +TA: TypeAlias = tuple[Unpack[Ts]] + +v1: TA[*list[int]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) + +v2: TA[Unpack[list[int]]] # E: "list[int]" cannot be unpacked (must be tuple or TypeVarTuple) +[builtins fixtures/tuple.pyi] From 00c333c526038f3f9947d9b10d61027ee0c21af8 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sun, 1 Feb 2026 11:53:29 +0000 Subject: [PATCH 28/28] Update check-type-aliases.test --- test-data/unit/check-type-aliases.test | 30 -------------------------- 1 file changed, 30 deletions(-) diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index e225593312f24..61eda2bd77747 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1237,36 +1237,6 @@ 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: ...