Skip to content

Commit 2f8f2b2

Browse files
committed
gh-92810: Automatically add ABC registry entries to cache
1 parent 7b6a0dc commit 2f8f2b2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Lib/_py_abc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ def register(cls, subclass):
6666
if issubclass(cls, subclass):
6767
# This would create a cycle, which is bad for the algorithm below
6868
raise RuntimeError("Refusing to create an inheritance cycle")
69+
# Add registry entry
6970
cls._abc_registry.add(subclass)
71+
# Automatically include cache entry
72+
cls._abc_cache.add(subclass)
7073
ABCMeta._abc_invalidation_counter += 1 # Invalidate negative cache
7174
return subclass
7275

Modules/_abc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,16 @@ _abc__abc_register_impl(PyObject *module, PyObject *self, PyObject *subclass)
613613
if (impl == NULL) {
614614
return NULL;
615615
}
616+
// Add registry entry
616617
if (_add_to_weak_set(impl, &impl->_abc_registry, subclass) < 0) {
617618
Py_DECREF(impl);
618619
return NULL;
619620
}
621+
// Automatically include cache entry
622+
if (_add_to_weak_set(impl, &impl->_abc_cache, subclass) < 0) {
623+
Py_DECREF(impl);
624+
return NULL;
625+
}
620626
Py_DECREF(impl);
621627

622628
/* Invalidate negative cache */

0 commit comments

Comments
 (0)