11import  unittest 
22from  test .support  import  (cpython_only , is_wasi , requires_limited_api , Py_DEBUG ,
3-                           set_recursion_limit , skip_on_s390x , skip_emscripten_stack_overflow )
3+                           set_recursion_limit , skip_on_s390x , skip_emscripten_stack_overflow ,  import_helper )
44try :
55    import  _testcapi 
66except  ImportError :
@@ -616,9 +616,6 @@ def testfunction_kw(self, *, kw):
616616    return  self 
617617
618618
619- ADAPTIVE_WARMUP_DELAY  =  2 
620- 
621- 
622619@unittest .skipIf (_testcapi  is  None , "requires _testcapi" ) 
623620class  TestPEP590 (unittest .TestCase ):
624621
@@ -802,17 +799,18 @@ def __call__(self, *args):
802799
803800    def  test_setvectorcall (self ):
804801        from  _testcapi  import  function_setvectorcall 
802+         _testinternalcapi  =  import_helper .import_module ("_testinternalcapi" )
805803        def  f (num ): return  num  +  1 
806804        assert_equal  =  self .assertEqual 
807805        num  =  10 
808806        assert_equal (11 , f (num ))
809807        function_setvectorcall (f )
810-         # make sure specializer is triggered by running > 50 times 
811-         for  _  in  range (10  *  ADAPTIVE_WARMUP_DELAY ):
808+         for  _  in  range (_testinternalcapi .SPECIALIZATION_THRESHOLD ):
812809            assert_equal ("overridden" , f (num ))
813810
814811    def  test_setvectorcall_load_attr_specialization_skip (self ):
815812        from  _testcapi  import  function_setvectorcall 
813+         _testinternalcapi  =  import_helper .import_module ("_testinternalcapi" )
816814
817815        class  X :
818816            def  __getattribute__ (self , attr ):
@@ -824,11 +822,12 @@ def __getattribute__(self, attr):
824822        function_setvectorcall (X .__getattribute__ )
825823        # make sure specialization doesn't trigger 
826824        # when vectorcall is overridden 
827-         for  _  in  range (ADAPTIVE_WARMUP_DELAY ):
825+         for  _  in  range (_testinternalcapi . SPECIALIZATION_THRESHOLD ):
828826            assert_equal ("overridden" , x .a )
829827
830828    def  test_setvectorcall_load_attr_specialization_deopt (self ):
831829        from  _testcapi  import  function_setvectorcall 
830+         _testinternalcapi  =  import_helper .import_module ("_testinternalcapi" )
832831
833832        class  X :
834833            def  __getattribute__ (self , attr ):
@@ -840,12 +839,12 @@ def get_a(x):
840839        assert_equal  =  self .assertEqual 
841840        x  =  X ()
842841        # trigger LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN specialization 
843-         for  _  in  range (ADAPTIVE_WARMUP_DELAY ):
842+         for  _  in  range (_testinternalcapi . SPECIALIZATION_THRESHOLD ):
844843            assert_equal ("a" , get_a (x ))
845844        function_setvectorcall (X .__getattribute__ )
846845        # make sure specialized LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN 
847846        # gets deopted due to overridden vectorcall 
848-         for  _  in  range (ADAPTIVE_WARMUP_DELAY ):
847+         for  _  in  range (_testinternalcapi . SPECIALIZATION_THRESHOLD ):
849848            assert_equal ("overridden" , get_a (x ))
850849
851850    @requires_limited_api  
0 commit comments