diff options
author | Randolf Scholz <randolf.scholz@gmail.com> | 2023-11-24 09:46:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-24 09:46:08 (GMT) |
commit | e9d1360c9a1072aa23950b321491dc542c3a19b8 (patch) | |
tree | d1475279265198f6cc44e4e53fb6be2b0e9a1a1b /Lib/typing.py | |
parent | d9fc15222e96942e30ea8b0561dec5c82ecb4663 (diff) | |
download | cpython-e9d1360c9a1072aa23950b321491dc542c3a19b8.zip cpython-e9d1360c9a1072aa23950b321491dc542c3a19b8.tar.gz cpython-e9d1360c9a1072aa23950b321491dc542c3a19b8.tar.bz2 |
gh-112345: `typing.Protocol`: Let failed subclasscheck show non-method members (#112344)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index a96c708..872aca8 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1828,8 +1828,13 @@ class _ProtocolMeta(ABCMeta): not cls.__callable_proto_members_only__ and cls.__dict__.get("__subclasshook__") is _proto_hook ): + non_method_attrs = sorted( + attr for attr in cls.__protocol_attrs__ + if not callable(getattr(cls, attr, None)) + ) raise TypeError( - "Protocols with non-method members don't support issubclass()" + "Protocols with non-method members don't support issubclass()." + f" Non-method members: {str(non_method_attrs)[1:-1]}." ) if not getattr(cls, '_is_runtime_protocol', False): raise TypeError( |