@@ -497,6 +497,42 @@ def __init__(self, arg):
497497
498498
499499class TestCallCache (TestBase ):
500+ @requires_jit_disabled
501+ @requires_specialization
502+ def test_call_builtin_class_custom_metaclass (self ):
503+ _testcapi = import_module ("_testcapi" )
504+
505+ def call (cls ):
506+ return cls ()
507+
508+ Meta = _testcapi .make_vectorcall_class (type )
509+ C = type .__new__ (Meta , "C" , (), {})
510+ Meta .set_vectorcall (C , type )
511+
512+ for _ in range (_testinternalcapi .SPECIALIZATION_THRESHOLD ):
513+ call (list )
514+ self .assert_specialized (call , "CALL_BUILTIN_CLASS" )
515+ Meta .__call__ = lambda cls : "custom"
516+ self .assertEqual (call (C ), "custom" )
517+
518+ @requires_jit_disabled
519+ @requires_specialization
520+ def test_call_immutable_class_custom_metaclass (self ):
521+ _testcapi = import_module ("_testcapi" )
522+ _testlimitedcapi = import_module ("_testlimitedcapi" )
523+
524+ def call (cls ):
525+ return cls ()
526+
527+ Meta = _testcapi .make_vectorcall_class (type )
528+ C = type .__new__ (Meta , "C" , (), {})
529+ Meta .set_vectorcall (C , type )
530+ _testlimitedcapi .type_freeze (C )
531+
532+ for _ in range (_testinternalcapi .SPECIALIZATION_THRESHOLD ):
533+ self .assertEqual (call (C ), "tp_call" )
534+ self .assert_specialized (call , "CALL_NON_PY_GENERAL" )
535+
500536 def test_too_many_defaults_0 (self ):
501537 def f ():
502538 pass
0 commit comments