Skip to content

Commit

Permalink
Fix recursive type alias crash in make_simplified_union (#15216)
Browse files Browse the repository at this point in the history
This is a recent regression
  • Loading branch information
ilevkivskyi committed May 10, 2023
1 parent 35acb1b commit fe7007f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def _remove_redundant_union_items(items: list[Type], keep_erased: bool) -> list[
continue

if is_proper_subtype(
proper_ti, tj, keep_erased_types=keep_erased, ignore_promotions=True
ti, tj, keep_erased_types=keep_erased, ignore_promotions=True
):
duplicate_index = j
break
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-recursive-types.test
Original file line number Diff line number Diff line change
Expand Up @@ -923,3 +923,17 @@ def dummy() -> None:
pass
reveal_type(bar) # N: Revealed type is "def [T <: builtins.dict[builtins.str, builtins.dict[builtins.str, builtins.str]]] (x: T`-1) -> T`-1"
[builtins fixtures/dict.pyi]

[case testAliasRecursiveUnpackMultiple]
from typing import Tuple, TypeVar, Optional

T = TypeVar("T")
S = TypeVar("S")

A = Tuple[T, S, Optional[A[T, S]]]
x: A[int, str]

*_, last = x
if last is not None:
reveal_type(last) # N: Revealed type is "Tuple[builtins.int, builtins.str, Union[Tuple[builtins.int, builtins.str, Union[..., None]], None]]"
[builtins fixtures/tuple.pyi]

0 comments on commit fe7007f

Please sign in to comment.