File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -671,6 +671,9 @@ 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
674677 # Use len(mro) as a proxy for the better choice.
675678 if len (t .type .mro ) > len (s .type .mro ):
676679 return True
Original file line number Diff line number Diff line change @@ -4460,3 +4460,26 @@ f2(a4) # E: Argument 1 to "f2" has incompatible type "A4"; expected "P2" \
44604460 # N: foo: expected "B1", got "str" \
44614461 # N: foo: expected setter type "C1", got "str"
44624462[builtins fixtures/property.pyi]
4463+
4464+
4465+ [case testExplicitProtocolJoinPreference]
4466+ from typing import Protocol, TypeVar
4467+
4468+ T = TypeVar("T")
4469+
4470+ class Proto1(Protocol):
4471+ def foo(self) -> int: ...
4472+ class Proto2(Proto1):
4473+ def bar(self) -> str: ...
4474+ class Proto3(Proto2):
4475+ def baz(self) -> str: ...
4476+
4477+ class Base: ...
4478+
4479+ class A(Base, Proto3): ...
4480+ class B(Base, Proto3): ...
4481+
4482+ def join(a: T, b: T) -> T: ...
4483+
4484+ def main(a: A, b: B) -> None:
4485+ reveal_type(join(a, b)) # N: Revealed type is "__main__.Proto3"
You can’t perform that action at this time.
0 commit comments