mirror of
https://github.com/python/cpython.git
synced 2025-10-16 19:57:59 +00:00
GH-114806. Don't specialize calls to classes with metaclasses. (GH-114870)
This commit is contained in:
parent
97cc58f977
commit
e66d0399cc
3 changed files with 24 additions and 0 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue