Skip to content

Commit

Permalink
BUG: Fix an issubclass failure for protocols with overloaded methods (
Browse files Browse the repository at this point in the history
#9904)

Co-authored-by: Shantanu <[email protected]>
  • Loading branch information
BvB93 and hauntsaninja authored Feb 20, 2022
1 parent 6698263 commit b22c4e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def non_method_protocol_members(tp: TypeInfo) -> List[str]:

for member in tp.protocol_members:
typ = get_proper_type(find_member(member, instance, instance))
if not isinstance(typ, CallableType):
if not isinstance(typ, (Overloaded, CallableType)):
result.append(member)
return result

Expand Down
13 changes: 12 additions & 1 deletion test-data/unit/check-protocols.test
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ y: PBad = None # E: Incompatible types in assignment (expression has type "None
[out]

[case testOnlyMethodProtocolUsableWithIsSubclass]
from typing import Protocol, runtime_checkable, Union, Type
from typing import Protocol, runtime_checkable, Union, Type, Sequence, overload
@runtime_checkable
class P(Protocol):
def meth(self) -> int:
Expand All @@ -2404,6 +2404,17 @@ if issubclass(cls, P):
reveal_type(cls) # N: Revealed type is "Type[__main__.C]"
else:
reveal_type(cls) # N: Revealed type is "Type[__main__.E]"

@runtime_checkable
class POverload(Protocol):
@overload
def meth(self, a: int) -> float: ...
@overload
def meth(self, a: str) -> Sequence[float]: ...
def meth(self, a):
pass

reveal_type(issubclass(int, POverload)) # N: Revealed type is "builtins.bool"
[builtins fixtures/isinstance.pyi]
[typing fixtures/typing-full.pyi]
[out]
Expand Down

0 comments on commit b22c4e4

Please sign in to comment.