diff options
author | Mark Shannon <mark@hotpy.org> | 2024-02-01 19:39:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-01 19:39:32 (GMT) |
commit | e66d0399cc2e78fcdb6a0113cd757d2ce567ca7c (patch) | |
tree | d10f93e048e5f0814607ac397e23e525b1dc0144 /Lib/test/test_class.py | |
parent | 97cc58f9777ee8b8e91f4ca8726cdb9f79cf906c (diff) | |
download | cpython-e66d0399cc2e78fcdb6a0113cd757d2ce567ca7c.zip cpython-e66d0399cc2e78fcdb6a0113cd757d2ce567ca7c.tar.gz cpython-e66d0399cc2e78fcdb6a0113cd757d2ce567ca7c.tar.bz2 |
GH-114806. Don't specialize calls to classes with metaclasses. (GH-114870)
Diffstat (limited to 'Lib/test/test_class.py')
-rw-r--r-- | Lib/test/test_class.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 1531aad..d592714 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -771,6 +771,22 @@ class ClassTests(unittest.TestCase): with self.assertRaises(RecursionError): add_one_level() + def testMetaclassCallOptimization(self): + calls = 0 + + class TypeMetaclass(type): + def __call__(cls, *args, **kwargs): + nonlocal calls + calls += 1 + return type.__call__(cls, *args, **kwargs) + + class Type(metaclass=TypeMetaclass): + def __init__(self, obj): + self._obj = obj + + for i in range(100): + Type(i) + self.assertEqual(calls, 100) if __name__ == '__main__': unittest.main() |