Skip to content

Commit dd0d18c

Browse files
committed
gh-92810: Revert _abc.c changes
1 parent b7603e0 commit dd0d18c

File tree

1 file changed

+1
-49
lines changed

1 file changed

+1
-49
lines changed

Modules/_abc.c

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -590,50 +590,6 @@ _abc__abc_register_impl(PyObject *module, PyObject *self, PyObject *subclass)
590590
}
591591
Py_DECREF(impl);
592592

593-
/* Recursively register the subclass in all ABC bases, to avoid recursive lookups.
594-
>>> class Ancestor1(ABC): pass
595-
>>> class Ancestor2(Ancestor1): pass
596-
>>> class Other: pass
597-
>>> Ancestor2.register(Other) # same result for Ancestor1.register(Other)
598-
>>> issubclass(Other, Ancestor2) is True
599-
>>> issubclass(Other, Ancestor1) is True
600-
*/
601-
PyObject *mro = PyObject_GetAttrString(self, "__mro__");
602-
if (mro == NULL) {
603-
return NULL;
604-
}
605-
606-
if (!PyTuple_CheckExact(mro)) {
607-
PyErr_SetString(PyExc_TypeError, "__mro__ must be an exact tuple");
608-
goto error;
609-
}
610-
611-
for (Py_ssize_t pos = 0; pos < PyTuple_GET_SIZE(mro); pos++) {
612-
PyObject *base_class = PyTuple_GET_ITEM(mro, pos); // borrowed
613-
PyObject *base_class_data;
614-
615-
if (PyObject_GetOptionalAttr(base_class,
616-
&_Py_ID(_abc_impl),
617-
&base_class_data) < 0)
618-
{
619-
goto error;
620-
}
621-
622-
if (base_class_data == NULL) {
623-
// not ABC class
624-
continue;
625-
}
626-
627-
_abc_data *base_class_state = _abc_data_CAST(base_class_data);
628-
int res = _add_to_weak_set(base_class_state,
629-
&base_class_state->_abc_registry,
630-
subclass);
631-
Py_DECREF(base_class_data);
632-
if (res < 0) {
633-
goto error;
634-
}
635-
}
636-
637593
/* Invalidate negative cache */
638594
increment_invalidation_counter(get_abc_state(module));
639595

@@ -648,10 +604,6 @@ _abc__abc_register_impl(PyObject *module, PyObject *self, PyObject *subclass)
648604
}
649605
}
650606
return Py_NewRef(subclass);
651-
652-
error:
653-
Py_XDECREF(mro);
654-
return NULL;
655607
}
656608

657609

@@ -878,7 +830,7 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
878830
}
879831
}
880832

881-
/* Recursive calls lead to uncontrolled negative cache growth, avoid this */
833+
/* No dice; update negative cache. */
882834
if (_add_to_weak_set(impl, &impl->_abc_negative_cache, subclass) < 0) {
883835
goto end;
884836
}

0 commit comments

Comments
 (0)