mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-91603: Speed up isinstance/issubclass on union types (GH-91631)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
This commit is contained in:
parent
4ed3900041
commit
0ef8d921f5
7 changed files with 24 additions and 79 deletions
|
@ -2625,6 +2625,10 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls
|
|||
return object_isinstance(inst, cls);
|
||||
}
|
||||
|
||||
if (_PyUnion_Check(cls)) {
|
||||
cls = _Py_union_args(cls);
|
||||
}
|
||||
|
||||
if (PyTuple_Check(cls)) {
|
||||
/* Not a general sequence -- that opens up the road to
|
||||
recursion and stack overflow. */
|
||||
|
@ -2714,6 +2718,10 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls)
|
|||
return recursive_issubclass(derived, cls);
|
||||
}
|
||||
|
||||
if (_PyUnion_Check(cls)) {
|
||||
cls = _Py_union_args(cls);
|
||||
}
|
||||
|
||||
if (PyTuple_Check(cls)) {
|
||||
|
||||
if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue