PEP 544 - Protocols subclassing normal classes
18 Feb
2022
18 Feb
'22
6:03 a.m.
In the resolution of PEP 544 this idea was discarded in order to preserve transitivity of subtyping: https://www.python.org/dev/peps/pep-0544/#protocols-subclassing-normal-class... However, the provided example is weird, because there is another seemingly straightforward and logical solution: `C` should not be a subtype of `Proto`! This behaviour would be useful, because it would allow to define Protocols that match any **subclass** of an existing class that also implement some extra feature. As a concrete, useful example this would allow for @runtime_checkable class namedtuple(Protocol, tuple): def _fields(self) -> tuple[str, ...]: ... which could be used to isinstance check for arbitrary namedtuples.
1002
Age (days ago)
1002
Last active (days ago)
0 comments
1 participants
participants (1)
-
Randolf Scholz