Skip to content

Commit 9b6f908

Browse files
committed
Normalize tuples before calculating the fallback
1 parent 8ed16d1 commit 9b6f908

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

mypy/semanal_shared.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
TypeVarLikeType,
4747
TypeVarTupleType,
4848
UnpackType,
49+
flatten_nested_tuples,
4950
get_proper_type,
5051
)
5152

@@ -290,7 +291,7 @@ def calculate_tuple_fallback(typ: TupleType) -> None:
290291
fallback = typ.partial_fallback
291292
assert fallback.type.fullname == "builtins.tuple"
292293
items = []
293-
for item in typ.items:
294+
for item in flatten_nested_tuples(typ.items):
294295
# TODO: this duplicates some logic in typeops.tuple_fallback().
295296
if isinstance(item, UnpackType):
296297
unpacked_type = get_proper_type(item.type)

test-data/unit/check-typevar-tuple.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,3 +2628,11 @@ def fn(f: Callable[[*tuple[T]], int]) -> Callable[[*tuple[T]], int]: ...
26282628
def test(*args: Unpack[tuple[T]]) -> int: ...
26292629
reveal_type(fn(test)) # N: Revealed type is "def [T] (T`1) -> builtins.int"
26302630
[builtins fixtures/tuple.pyi]
2631+
2632+
[case testNoCrashSubclassingTUpleWithTrivialUnpack]
2633+
# https://github.com/python/mypy/issues/19105
2634+
from typing import Unpack
2635+
2636+
class A(tuple[Unpack[tuple[int]]]): ...
2637+
class B(tuple[Unpack[tuple[()]]]): ...
2638+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)