[issue30230] Move quick test in PyObject_IsSubClass outside if PyType_CheckExact guard
Jim Fasarakis-Hilliard
report at bugs.python.org
Tue May 2 10:30:45 EDT 2017
New submission from Jim Fasarakis-Hilliard:
Currently the first lines in PyObject_IsSubClass are:
/* We know what type's __subclasscheck__ does. */
if (PyType_CheckExact(cls)) {
/* Quick test for an exact match */
if (derived == cls)
return 1;
return recursive_issubclass(derived, cls);
}
The if (derived == cls) runs only if PyType_CheckExact is True which doesn't hold for any classes with a custom metaclass. As a result, a check of the form issubclass(Sequence, Sequence) will take a slow path that invokes __subclasscheck__.
I'm not sure if this was placed inside there due to some wild edge-case, though. PyObject_IsInstance uses the same trick and does so outside the if (PyType_CheckExact(cls)) check.
I'll gladly submit a PR if this indeed needs fixing and not by design.
----------
components: Interpreter Core
messages: 292764
nosy: Jim Fasarakis-Hilliard
priority: normal
severity: normal
status: open
title: Move quick test in PyObject_IsSubClass outside if PyType_CheckExact guard
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30230>
_______________________________________
More information about the Python-bugs-list
mailing list