summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2023-05-25 16:43:40 (GMT)
committerGitHub <noreply@github.com>2023-05-25 16:43:40 (GMT)
commit2b7027d0b2ee2e102a24a0da27d01b8221f9351c (patch)
tree89fcf158a87d80b7799ee8daf51883bcdad23db0 /Lib/typing.py
parent77d7ec5aa978db05cfb6f83e7624ca195065ce11 (diff)
downloadcpython-2b7027d0b2ee2e102a24a0da27d01b8221f9351c.zip
cpython-2b7027d0b2ee2e102a24a0da27d01b8221f9351c.tar.gz
cpython-2b7027d0b2ee2e102a24a0da27d01b8221f9351c.tar.bz2
gh-104935: typing: Fix interactions between `@runtime_checkable` and `Generic` (#104939)
--------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index b32ff0c..85d129b 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1894,7 +1894,7 @@ class Protocol(Generic, metaclass=_ProtocolMeta):
annotations = getattr(base, '__annotations__', {})
if (isinstance(annotations, collections.abc.Mapping) and
attr in annotations and
- issubclass(other, Generic) and other._is_protocol):
+ issubclass(other, Generic) and getattr(other, '_is_protocol', False)):
break
else:
return NotImplemented
@@ -1912,7 +1912,7 @@ class Protocol(Generic, metaclass=_ProtocolMeta):
if not (base in (object, Generic) or
base.__module__ in _PROTO_ALLOWLIST and
base.__name__ in _PROTO_ALLOWLIST[base.__module__] or
- issubclass(base, Generic) and base._is_protocol):
+ issubclass(base, Generic) and getattr(base, '_is_protocol', False)):
raise TypeError('Protocols can only inherit from other'
' protocols, got %r' % base)
if cls.__init__ is Protocol.__init__:
@@ -2059,7 +2059,7 @@ def runtime_checkable(cls):
Warning: this will check only the presence of the required methods,
not their type signatures!
"""
- if not issubclass(cls, Generic) or not cls._is_protocol:
+ if not issubclass(cls, Generic) or not getattr(cls, '_is_protocol', False):
raise TypeError('@runtime_checkable can be only applied to protocol classes,'
' got %r' % cls)
cls._is_runtime_protocol = True