diff --git a/mypy/solve.py b/mypy/solve.py index 023a32dbd04b..098d926bc789 100644 --- a/mypy/solve.py +++ b/mypy/solve.py @@ -250,6 +250,8 @@ def solve_iteratively( def _join_sorted_key(t: Type) -> int: t = get_proper_type(t) if isinstance(t, UnionType): + return -2 + if isinstance(t, NoneType): return -1 return 0 diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index 35357f8c930f..763e9b25f97c 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -3602,4 +3602,17 @@ def draw( reveal_type(c1) # N: Revealed type is "Union[builtins.int, builtins.str]" reveal_type(c2) # N: Revealed type is "Union[builtins.int, builtins.str]" reveal_type(c3) # N: Revealed type is "Union[builtins.int, builtins.str]" + +def takes_int_str_none(x: int | str | None) -> None: ... + +def draw_none( + colors1: A[str] | B[str] | C[int] | D[None], + colors2: A[str] | B[str] | C[int] | D[None], + colors3: A[str] | B[str] | C[int] | D[None], +) -> None: + for c1, c2, c3 in zip2(colors1, colors2, colors3): + # TODO: can't do reveal type because the union order is not deterministic + takes_int_str_none(c1) + takes_int_str_none(c2) + takes_int_str_none(c3) [builtins fixtures/tuple.pyi] diff --git a/test-data/unit/check-varargs.test b/test-data/unit/check-varargs.test index c59f07e92a4e..2e93c761b0be 100644 --- a/test-data/unit/check-varargs.test +++ b/test-data/unit/check-varargs.test @@ -631,7 +631,7 @@ T = TypeVar('T') def f(*args: T) -> T: ... reveal_type(f(*(1, None))) # N: Revealed type is "Union[Literal[1]?, None]" reveal_type(f(1, *(None, 1))) # N: Revealed type is "Union[Literal[1]?, None]" -reveal_type(f(1, *(1, None))) # N: Revealed type is "Union[builtins.int, None]" +reveal_type(f(1, *(1, None))) # N: Revealed type is "Union[Literal[1]?, None]" [builtins fixtures/tuple.pyi]