summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorAlex Waygood <Alex.Waygood@Gmail.com>2023-04-05 09:07:30 (GMT)
committerGitHub <noreply@github.com>2023-04-05 09:07:30 (GMT)
commit47753ecde21b79b5c5f11d883946fda2a340e427 (patch)
tree789ef8f5b0a6772138aad1cf51e8b29d392689fe /Lib/typing.py
parent264c00a1c512a9bd58f47c80e72e436c639763c8 (diff)
downloadcpython-47753ecde21b79b5c5f11d883946fda2a340e427.zip
cpython-47753ecde21b79b5c5f11d883946fda2a340e427.tar.gz
cpython-47753ecde21b79b5c5f11d883946fda2a340e427.tar.bz2
gh-74690: typing: Simplify and optimise `_ProtocolMeta.__instancecheck__` (#103159)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py14
1 files changed, 3 insertions, 11 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 442d684..f50e9b0 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -2024,20 +2024,12 @@ class _ProtocolMeta(ABCMeta):
raise TypeError("Instance and class checks can only be used with"
" @runtime_checkable protocols")
- if not is_protocol_cls and issubclass(instance.__class__, cls):
- return True
-
- protocol_attrs = _get_protocol_attrs(cls)
-
- if (
- _is_callable_members_only(cls, protocol_attrs)
- and issubclass(instance.__class__, cls)
- ):
+ if super().__instancecheck__(instance):
return True
if is_protocol_cls:
getattr_static = _lazy_load_getattr_static()
- for attr in protocol_attrs:
+ for attr in _get_protocol_attrs(cls):
try:
val = getattr_static(instance, attr)
except AttributeError:
@@ -2047,7 +2039,7 @@ class _ProtocolMeta(ABCMeta):
else:
return True
- return super().__instancecheck__(instance)
+ return False
class Protocol(Generic, metaclass=_ProtocolMeta):