@@ -1069,7 +1069,7 @@ def write(items):
10691069 opname = "STORE_SUBSCR_LIST_INT"
10701070 self .assert_races_do_not_crash (opname , get_items , read , write )
10711071
1072- @requires_specialization
1072+ @requires_specialization_ft
10731073 def test_unpack_sequence_list (self ):
10741074 def get_items ():
10751075 items = []
@@ -1245,6 +1245,14 @@ def f(o, n):
12451245 f (test_obj , 1 )
12461246 self .assertEqual (test_obj .b , 0 )
12471247
1248+ # gh-127274: BINARY_SUBSCR_GETITEM will only cache __getitem__ methods that
1249+ # are deferred. We only defer functions defined at the top-level.
1250+ class CGetItem :
1251+ def __init__ (self , val ):
1252+ self .val = val
1253+ def __getitem__ (self , item ):
1254+ return self .val
1255+
12481256
12491257class TestSpecializer (TestBase ):
12501258
@@ -1520,6 +1528,15 @@ def binary_subscr_str_int():
15201528 self .assert_specialized (binary_subscr_str_int , "BINARY_SUBSCR_STR_INT" )
15211529 self .assert_no_opcode (binary_subscr_str_int , "BINARY_SUBSCR" )
15221530
1531+ def binary_subscr_getitems ():
1532+ items = [CGetItem (i ) for i in range (100 )]
1533+ for i in range (100 ):
1534+ self .assertEqual (items [i ][i ], i )
1535+
1536+ binary_subscr_getitems ()
1537+ self .assert_specialized (binary_subscr_getitems , "BINARY_SUBSCR_GETITEM" )
1538+ self .assert_no_opcode (binary_subscr_getitems , "BINARY_SUBSCR" )
1539+
15231540
15241541if __name__ == "__main__" :
15251542 unittest .main ()
0 commit comments