Skip to content

Commit 34e0a0c

Browse files
committed
fix test
1 parent 69c1a65 commit 34e0a0c

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

mypy/join.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,10 @@ def is_better(t: Type, s: Type) -> bool:
671671
if isinstance(t, Instance):
672672
if not isinstance(s, Instance):
673673
return True
674-
if t.type.is_protocol != s.type.is_protocol and s.type.fullname != "builtins.object":
675-
# mro of protocol is not really relevant
676-
return not t.type.is_protocol
674+
if t.type.is_protocol != s.type.is_protocol:
675+
if t.type.fullname != "builtins.object" and s.type.fullname != "builtins.object":
676+
# mro of protocol is not really relevant
677+
return not t.type.is_protocol
677678
# Use len(mro) as a proxy for the better choice.
678679
if len(t.type.mro) > len(s.type.mro):
679680
return True

test-data/unit/check-inference.test

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3889,7 +3889,7 @@ def a4(x: List[str], y: List[Never]) -> None:
38893889
[builtins fixtures/dict.pyi]
38903890

38913891

3892-
[case testNonDeterminismFromNonCommuativeJoinInvolvingProtocolBaseAndPromotableType]
3892+
[case testDeterminismCommutativityWithJoinInvolvingProtocolBaseAndPromotableType]
38933893
# flags: --python-version 3.11
38943894
# Regression test for https://github.com/python/mypy/issues/16979#issuecomment-1982246306
38953895
from __future__ import annotations
@@ -3907,13 +3907,6 @@ class _SupportsCompare(Protocol):
39073907
class Comparable(_SupportsCompare):
39083908
pass
39093909

3910-
class A(Generic[T, U]):
3911-
@overload
3912-
def __init__(self: A[T, T], a: T, b: T, /) -> None: ... # type: ignore[overload-overlap]
3913-
@overload
3914-
def __init__(self: A[T, U], a: T, b: U, /) -> Never: ...
3915-
def __init__(self, *a) -> None: ...
3916-
39173910
comparable: Comparable = Comparable()
39183911

39193912
from typing import _promote
@@ -3925,9 +3918,21 @@ class floatlike:
39253918
class intlike:
39263919
def __lt__(self, other: intlike, /) -> bool: ...
39273920

3921+
3922+
class A(Generic[T, U]):
3923+
@overload
3924+
def __init__(self: A[T, T], a: T, b: T, /) -> None: ... # type: ignore[overload-overlap]
3925+
@overload
3926+
def __init__(self: A[T, U], a: T, b: U, /) -> Never: ...
3927+
def __init__(self, *a) -> None: ...
3928+
3929+
def join(a: T, b: T) -> T: ...
3930+
3931+
reveal_type(join(intlike(), comparable)) # N: Revealed type is "__main__._SupportsCompare"
39283932
reveal_type(A(intlike(), comparable)) # N: Revealed type is "__main__.A[__main__._SupportsCompare, __main__._SupportsCompare]"
39293933
[builtins fixtures/tuple.pyi]
39303934
[typing fixtures/typing-medium.pyi]
3935+
39313936
[case testTupleJoinFallbackInference]
39323937
foo = [
39333938
(1, ("a", "b")),

0 commit comments

Comments
 (0)