@@ -36,6 +36,13 @@ def count_instr_recursively(f, opname):
36
36
return count
37
37
38
38
39
+ def get_binop_argval (arg ):
40
+ for i , nb_op in enumerate (opcode ._nb_ops ):
41
+ if arg == nb_op [0 ]:
42
+ return i
43
+ assert False , f"{ arg } is not a valid BINARY_OP argument."
44
+
45
+
39
46
class TestTranforms (BytecodeTestCase ):
40
47
41
48
def check_jump_targets (self , code ):
@@ -518,8 +525,7 @@ def test_folding_subscript(self):
518
525
('("a" * 10)[10]' , True ),
519
526
('(1, (1, 2))[2:6][0][2-1]' , True ),
520
527
]
521
- subscr_argval = 26
522
- assert opcode ._nb_ops [subscr_argval ][0 ] == 'NB_SUBSCR'
528
+ subscr_argval = get_binop_argval ('NB_SUBSCR' )
523
529
for expr , has_error in tests :
524
530
with self .subTest (expr = expr , has_error = has_error ):
525
531
code = compile (expr , '' , 'single' )
@@ -1068,7 +1074,7 @@ def test_multiple_foldings(self):
1068
1074
('LOAD_SMALL_INT' , 2 , 0 ),
1069
1075
('BUILD_TUPLE' , 1 , 0 ),
1070
1076
('LOAD_SMALL_INT' , 0 , 0 ),
1071
- ('BINARY_SUBSCR ' , None , 0 ),
1077
+ ('BINARY_OP ' , get_binop_argval ( 'NB_SUBSCR' ) , 0 ),
1072
1078
('BUILD_TUPLE' , 2 , 0 ),
1073
1079
('RETURN_VALUE' , None , 0 )
1074
1080
]
0 commit comments