gh-92810: Address review fixes

This commit is contained in:
Martynov Maxim 2025-12-23 10:59:47 +03:00
parent b294760cf4
commit 5813a8183a
No known key found for this signature in database
GPG key ID: 9C23E39F5BBC88CC
2 changed files with 6 additions and 5 deletions

View file

@ -833,7 +833,7 @@ abc
* Reduce memory usage of :func:`issubclass` checks for classes inheriting abstract classes.
:class:`abc.ABCMeta` hook ``__subclasscheck__`` now includes
a guard which is triggered then the hook is called from a parent class
a guard which is triggered when the hook is called from a parent class
(``issubclass(cls, RootClass)`` -> ``issubclass(cls, NestedClass)`` -> ...).
This guard prevents adding ``cls`` to ``NestedClass`` positive and negative caches,
preventing memory bloat in some cases (thousands of classes inherited from ABC).

View file

@ -12,6 +12,7 @@ import abc
import _py_abc
from inspect import isabstract
def test_factory(abc_ABCMeta, abc_get_cache_token):
class TestLegacyAPI(unittest.TestCase):
@ -73,22 +74,22 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
def check_isinstance(self, obj, target_class):
self.assertIsInstance(obj, target_class)
self.assertIsInstance(obj, (target_class,))
self.assertIsInstance(obj, target_class | target_class)
self.assertIsInstance(obj, target_class | int)
def check_not_isinstance(self, obj, target_class):
self.assertNotIsInstance(obj, target_class)
self.assertNotIsInstance(obj, (target_class,))
self.assertNotIsInstance(obj, target_class | target_class)
self.assertNotIsInstance(obj, target_class | int)
def check_issubclass(self, klass, target_class):
self.assertIsSubclass(klass, target_class)
self.assertIsSubclass(klass, (target_class,))
self.assertIsSubclass(klass, target_class | target_class)
self.assertIsSubclass(klass, target_class | int)
def check_not_issubclass(self, klass, target_class):
self.assertNotIsSubclass(klass, target_class)
self.assertNotIsSubclass(klass, (target_class,))
self.assertNotIsSubclass(klass, target_class | target_class)
self.assertNotIsSubclass(klass, target_class | int)
def test_ABC_helper(self):
# create an ABC using the helper class and perform basic checks