diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-06-05 13:36:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-05 13:36:51 (GMT) |
commit | cdfb201bfa35b7c50de5099c6d9078c806851d98 (patch) | |
tree | 8e0da082af08ed04818003402f486041ee8e6bc4 /Lib/typing.py | |
parent | 69d1245685cf95ddc678633e978a56673da64865 (diff) | |
download | cpython-cdfb201bfa35b7c50de5099c6d9078c806851d98.zip cpython-cdfb201bfa35b7c50de5099c6d9078c806851d98.tar.gz cpython-cdfb201bfa35b7c50de5099c6d9078c806851d98.tar.bz2 |
gh-105237: Allow calling `issubclass(X, typing.Protocol)` again (#105239)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index f589be7..c831ba8 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1782,6 +1782,8 @@ class _ProtocolMeta(ABCMeta): ) def __subclasscheck__(cls, other): + if cls is Protocol: + return type.__subclasscheck__(cls, other) if not isinstance(other, type): # Same error message as for issubclass(1, int). raise TypeError('issubclass() arg 1 must be a class') @@ -1803,6 +1805,8 @@ class _ProtocolMeta(ABCMeta): def __instancecheck__(cls, instance): # We need this method for situations where attributes are # assigned in __init__. + if cls is Protocol: + return type.__instancecheck__(cls, instance) if not getattr(cls, "_is_protocol", False): # i.e., it's a concrete subclass of a protocol return super().__instancecheck__(instance) |