Skip to content

Commit fe7007f

Browse files
authored
Fix recursive type alias crash in make_simplified_union (#15216)
This is a recent regression
1 parent 35acb1b commit fe7007f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

mypy/typeops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def _remove_redundant_union_items(items: list[Type], keep_erased: bool) -> list[
528528
continue
529529

530530
if is_proper_subtype(
531-
proper_ti, tj, keep_erased_types=keep_erased, ignore_promotions=True
531+
ti, tj, keep_erased_types=keep_erased, ignore_promotions=True
532532
):
533533
duplicate_index = j
534534
break

test-data/unit/check-recursive-types.test

+14
Original file line numberDiff line numberDiff line change
@@ -923,3 +923,17 @@ def dummy() -> None:
923923
pass
924924
reveal_type(bar) # N: Revealed type is "def [T <: builtins.dict[builtins.str, builtins.dict[builtins.str, builtins.str]]] (x: T`-1) -> T`-1"
925925
[builtins fixtures/dict.pyi]
926+
927+
[case testAliasRecursiveUnpackMultiple]
928+
from typing import Tuple, TypeVar, Optional
929+
930+
T = TypeVar("T")
931+
S = TypeVar("S")
932+
933+
A = Tuple[T, S, Optional[A[T, S]]]
934+
x: A[int, str]
935+
936+
*_, last = x
937+
if last is not None:
938+
reveal_type(last) # N: Revealed type is "Tuple[builtins.int, builtins.str, Union[Tuple[builtins.int, builtins.str, Union[..., None]], None]]"
939+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)