Skip to content

Commit b22c4e4

Browse files
BvB93hauntsaninja
andauthored
BUG: Fix an issubclass failure for protocols with overloaded methods (python#9904)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
1 parent 6698263 commit b22c4e4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

mypy/subtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ def non_method_protocol_members(tp: TypeInfo) -> List[str]:
763763

764764
for member in tp.protocol_members:
765765
typ = get_proper_type(find_member(member, instance, instance))
766-
if not isinstance(typ, CallableType):
766+
if not isinstance(typ, (Overloaded, CallableType)):
767767
result.append(member)
768768
return result
769769

test-data/unit/check-protocols.test

+12-1
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ y: PBad = None # E: Incompatible types in assignment (expression has type "None
23822382
[out]
23832383

23842384
[case testOnlyMethodProtocolUsableWithIsSubclass]
2385-
from typing import Protocol, runtime_checkable, Union, Type
2385+
from typing import Protocol, runtime_checkable, Union, Type, Sequence, overload
23862386
@runtime_checkable
23872387
class P(Protocol):
23882388
def meth(self) -> int:
@@ -2404,6 +2404,17 @@ if issubclass(cls, P):
24042404
reveal_type(cls) # N: Revealed type is "Type[__main__.C]"
24052405
else:
24062406
reveal_type(cls) # N: Revealed type is "Type[__main__.E]"
2407+
2408+
@runtime_checkable
2409+
class POverload(Protocol):
2410+
@overload
2411+
def meth(self, a: int) -> float: ...
2412+
@overload
2413+
def meth(self, a: str) -> Sequence[float]: ...
2414+
def meth(self, a):
2415+
pass
2416+
2417+
reveal_type(issubclass(int, POverload)) # N: Revealed type is "builtins.bool"
24072418
[builtins fixtures/isinstance.pyi]
24082419
[typing fixtures/typing-full.pyi]
24092420
[out]

0 commit comments

Comments
 (0)