-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixesstdlibPython modules in the Lib dirPython modules in the Lib dirtopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
On Python 3.11:
>>> from typing import *
>>> @runtime_checkable
... class Foo(Protocol):
... x = 1
... @classmethod
... def __subclasshook__(cls, other):
... return hasattr(other, 'x')
...
>>> issubclass(object, Foo)
False
On Python 3.12:
>>> from typing import *
>>> @runtime_checkable
... class Foo(Protocol):
... x = 1
... @classmethod
... def __subclasshook__(cls, other):
... return hsattr(cls, 'x')
...
>>> issubclass(object, Foo)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1829, in __subclasscheck__
raise TypeError(
TypeError: Protocols with non-method members don't support issubclass()
I think I prefer the Python 3.11 behaviour here, since the whole point of allowing protocols to define custom __subclasshook__
methods is so that users can customise how issubclass()
works on user-defined protocols.
Linked PRs
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixesstdlibPython modules in the Lib dirPython modules in the Lib dirtopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error