Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Description
PEP-695 protocols don't work as intended:
Here's the behaviour you get with protocols that use pre-PEP 695 syntax, which is correct:
>>>from typingimport Protocol, runtime_checkable, TypeVar>>> T_co= TypeVar("T_co",covariant=True)>>>@runtime_checkable...classSupportsAbsOld(Protocol[T_co]):...def__abs__(self) -> T_co:.........>>>isinstance(0, SupportsAbsOld)True>>>issubclass(float, SupportsAbsOld)True
And here's the behaviour you get onmain with protocols that use PEP 695 syntax, which is incorrect:
>>>@runtime_checkable...class SupportsAbsNew[T_co](Protocol):...def__abs__(self) -> T_co:.........>>>isinstance(0, SupportsAbsNew)False>>>issubclass(float, SupportsAbsNew)Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\alexw\coding\cpython\Lib\abc.py", line 123, in __subclasscheck__ return _abc_subclasscheck(cls, subclass) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1875, in _proto_hook raise TypeError("Protocols with non-method members"TypeError: Protocols with non-method members don't support issubclass()