Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f757b72

Browse files
authored
bpo-33018 (GH-5944) fixed bpo-32999 too. So fc7df0e is not required anymore. Revert it except test case.
1 parent 40472dd commit f757b72

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

Modules/_abc.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ _Py_IDENTIFIER(__abstractmethods__);
1616
_Py_IDENTIFIER(__class__);
1717
_Py_IDENTIFIER(__dict__);
1818
_Py_IDENTIFIER(__bases__);
19-
_Py_IDENTIFIER(__mro__);
2019
_Py_IDENTIFIER(_abc_impl);
2120
_Py_IDENTIFIER(__subclasscheck__);
2221
_Py_IDENTIFIER(__subclasshook__);
@@ -574,7 +573,7 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
574573
return NULL;
575574
}
576575

577-
PyObject *ok, *mro = NULL, *subclasses = NULL, *result = NULL;
576+
PyObject *ok, *subclasses = NULL, *result = NULL;
578577
Py_ssize_t pos;
579578
int incache;
580579
_abc_data *impl = _get_impl(self);
@@ -643,31 +642,20 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
643642
}
644643
Py_DECREF(ok);
645644

646-
/* 4. Check if it's a direct subclass.
647-
*
648-
* if cls in getattr(subclass, '__mro__', ()):
649-
* cls._abc_cache.add(subclass)
650-
* return True
651-
*/
652-
if (_PyObject_LookupAttrId(subclass, &PyId___mro__, &mro) < 0) {
653-
goto end;
654-
}
655-
if (mro != NULL) {
656-
if (!PyTuple_Check(mro)) {
657-
// Python version supports non-tuple iterable. Keep it as
658-
// implementation detail.
659-
PyErr_SetString(PyExc_TypeError, "__mro__ is not a tuple");
645+
/* 4. Check if it's a direct subclass. */
646+
PyObject *mro = ((PyTypeObject *)subclass)->tp_mro;
647+
assert(PyTuple_Check(mro));
648+
for (pos = 0; pos < PyTuple_GET_SIZE(mro); pos++) {
649+
PyObject *mro_item = PyTuple_GET_ITEM(mro, pos);
650+
if (mro_item == NULL) {
660651
goto end;
661652
}
662-
for (pos = 0; pos < PyTuple_GET_SIZE(mro); pos++) {
663-
PyObject *mro_item = PyTuple_GET_ITEM(mro, pos);
664-
if ((PyObject *)self == mro_item) {
665-
if (_add_to_weak_set(&impl->_abc_cache, subclass) < 0) {
666-
goto end;
667-
}
668-
result = Py_True;
653+
if ((PyObject *)self == mro_item) {
654+
if (_add_to_weak_set(&impl->_abc_cache, subclass) < 0) {
669655
goto end;
670656
}
657+
result = Py_True;
658+
goto end;
671659
}
672660
}
673661

@@ -708,7 +696,6 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
708696

709697
end:
710698
Py_DECREF(impl);
711-
Py_XDECREF(mro);
712699
Py_XDECREF(subclasses);
713700
Py_XINCREF(result);
714701
return result;

0 commit comments

Comments
 (0)