From 5b52987b8f7cd1a75e8b17aa7f3c353bf7838eb4 Mon Sep 17 00:00:00 2001 From: Bas van Beek Date: Tue, 12 Jan 2021 21:26:28 +0100 Subject: [PATCH] BUG: Fix an `issubclass` failure for protocols with overloaded methods --- mypy/subtypes.py | 2 +- test-data/unit/check-protocols.test | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mypy/subtypes.py b/mypy/subtypes.py index 81726b1f9884..c6c62d208fb2 100644 --- a/mypy/subtypes.py +++ b/mypy/subtypes.py @@ -712,7 +712,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 diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index 30d33b917123..b264d4d8b0e9 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -2197,7 +2197,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: @@ -2219,6 +2219,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]