[issue32999] issubclass(obj, abc.ABC) causes a segfault
Alexey Izbyshev
report at bugs.python.org
Mon Mar 5 15:46:38 EST 2018
Alexey Izbyshev <izbyshev at ispras.ru> added the comment:
I've also checked that ABC.register() doesn't allow non-classes (and PEP 3119 mentions that).
Looking at PyObject_IsSubclass in Objects/abstract.c, the only case in which its check_class() could be avoided is if there is a custom __subclasscheck__:
>>> class M(type):
... def __subclasscheck__(cls, c):
... return c == 1 or super().__subclasscheck__(c)
...
>>> class A(metaclass=M):
... pass
...
>>> issubclass(1, A)
True
If there is no need to support such weird __subclasscheck__, check_class() could be called earlier.
Note, however, that check_class() treats anything having __bases__ as a class, so moving the check alone is not enough to avoid the crash in all cases.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32999>
_______________________________________
More information about the Python-bugs-list
mailing list