mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
gh-92810: Address review fixes
This commit is contained in:
parent
b294760cf4
commit
5813a8183a
2 changed files with 6 additions and 5 deletions
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue