You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot call issubclass() against typing.Protocol on Python 3.12 #105237
But on Python 3.12 (following the backport of c05c31d), this raises:
>>> 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.
While working on fixing the bug, we discovered another bug, where issubclass(object, Protocol) can sometimes evaluate to True. Unlike the original bug, this one reproduces all the way back to Python 3.8. It's now fixed on main and 3.12, but it might be good to see if we can fix it on 3.11 as well.
While working on fixing the bug, we discovered another bug, where issubclass(object, Protocol) can sometimes evaluate to True. Unlike the original bug, this one reproduces all the way back to Python 3.8. It's now fixed on main and 3.12, but it might be good to see if we can fix it on 3.11 as well.
Well, but on the other hand, I'm hesitant to touch 3.11 here, given that it's an edge-case bug, and it's hard to do a proper fix that's not somewhat invasive. So, I'll close this for now. (But if somebody else disagrees and wants to have a go at fixing it on 3.11, happy to reopen.)
Activity
gh-105237: Allow calling `issubclass(X, typing.Protocol)` again (#105239
pythongh-105237: Allow calling `issubclass(X, typing.Protocol)` again (…
[3.12] gh-105237: Allow calling `issubclass(X, typing.Protocol)` again (
AlexWaygood commentedon Jun 5, 2023
While working on fixing the bug, we discovered another bug, where
issubclass(object, Protocol)can sometimes evaluate toTrue. Unlike the original bug, this one reproduces all the way back to Python 3.8. It's now fixed onmainand 3.12, but it might be good to see if we can fix it on 3.11 as well.AlexWaygood commentedon Jun 5, 2023
Well, but on the other hand, I'm hesitant to touch 3.11 here, given that it's an edge-case bug, and it's hard to do a proper fix that's not somewhat invasive. So, I'll close this for now. (But if somebody else disagrees and wants to have a go at fixing it on 3.11, happy to reopen.)