8000 gh-92810: Reduce memory usage by ABCMeta.__subclasscheck__ by dolfinus · Pull Request #131914 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-92810: Reduce memory usage by ABCMeta.__subclasscheck__ #131914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gh-92810: Fix linter errors
  • Loading branch information
dolfinus committed Apr 21, 2025
commit 8d695fd1cac081f66278548fcfa535e5dd051fbc
2 changes: 1 addition & 1 deletion Lib/_py_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __subclasscheck__(cls, subclass):
# Check if it's a subclass of a subclass (recursive)
for scls in cls.__subclasses__():
# If inside recursive issubclass check, avoid adding classes to any cache because this
# may drastically increase memory usage.
# may drastically increase memory usage.
# Unfortunately, issubclass/__subclasscheck__ don't accept third argument with context,
# so using global context within ABCMeta.
# This is done only on first method call, others will use cached result.
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def __subclasses__(cls):

class Parent2(metaclass=abc_ABCMeta):
__subclasses__ = lambda: [A]

# trigger caching
for _ in range(2):
self.assertIsInstance(A(), Parent1)
Expand Down
2 changes: 0 additions & 2 deletions Modules/_abc.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,6 @@ _abc__abc_register_impl(PyObject *module, PyObject *self, PyObject *subclass)
if (result < 0) {
return NULL;
}

/* Actual registration */
_abc_data *impl = _get_impl(module, self);
if (impl == NULL) {
return NULL;
Expand Down
Loading
0