>>> import typing
>>> issubclass(object, typing.Protocol)
False
>>> import typing
>>> issubclass(object, typing.Protocol)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1797, in __subclasscheck__
raise TypeError(
TypeError: Instance and class checks can only be used with @runtime_checkable protocols
The new behaviour doesn't make sense. That TypeError should only be triggered if a user is calling issubclass() against a subclass of typing.Protocol. typing.Protocol itself should be exempted.
Bug report
On Python 3.11, you can do this:
But on Python 3.12 (following the backport of c05c31d), this raises:
The new behaviour doesn't make sense. That
TypeErrorshould only be triggered if a user is callingissubclass()against a subclass oftyping.Protocol.typing.Protocolitself should be exempted.Linked PRs
issubclass(X, typing.Protocol)again #105239issubclass(X, typing.Protocol)again (GH-105239) #105316