Skip to content

Commit b35fba1

Browse files
committed
Fix nondeterministic type checking caused by nonassociative of None joins
1 parent f328ad6 commit b35fba1

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

mypy/solve.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ def solve_iteratively(
250250
def _join_sorted_key(t: Type) -> int:
251251
t = get_proper_type(t)
252252
if isinstance(t, UnionType):
253+
return -2
254+
if isinstance(t, NoneType):
253255
return -1
254256
return 0
255257

test-data/unit/check-generics.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3602,4 +3602,17 @@ def draw(
36023602
reveal_type(c1) # N: Revealed type is "Union[builtins.int, builtins.str]"
36033603
reveal_type(c2) # N: Revealed type is "Union[builtins.int, builtins.str]"
36043604
reveal_type(c3) # N: Revealed type is "Union[builtins.int, builtins.str]"
3605+
3606+
def takes_int_str_none(x: int | str | None) -> None: ...
3607+
3608+
def draw_none(
3609+
colors1: A[str] | B[str] | C[int] | D[None],
3610+
colors2: A[str] | B[str] | C[int] | D[None],
3611+
colors3: A[str] | B[str] | C[int] | D[None],
3612+
) -> None:
3613+
for c1, c2, c3 in zip2(colors1, colors2, colors3):
3614+
# TODO: can't do reveal type because the union order is not deterministic
3615+
takes_int_str_none(c1)
3616+
takes_int_str_none(c2)
3617+
takes_int_str_none(c3)
36053618
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)