Skip to content

Commit c481698

Browse files
address reviews
1 parent 844cc42 commit c481698

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def iter_ops(ex):
6767
def get_ops(ex):
6868
return list(iter_ops(ex))
6969

70-
def matching_opnames(ex, name):
71-
return [opname for opname in iter_opnames(ex) if opname == name]
70+
def count_ops(ex, name):
71+
return len([opname for opname in iter_opnames(ex) if opname == name])
7272

7373

7474
@requires_specialization
@@ -1921,8 +1921,8 @@ def testfunc(n):
19211921
self.assertIn("_BINARY_OP_SUBSCR_STR_INT", uops)
19221922
self.assertIn("_COMPARE_OP_STR", uops)
19231923
self.assertIn("_POP_TOP_NOP", uops)
1924-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
1925-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP_INT")), 1)
1924+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
1925+
self.assertLessEqual(count_ops(ex, "_POP_TOP_INT"), 1)
19261926

19271927
def test_call_type_1_guards_removed(self):
19281928
def testfunc(n):
@@ -2214,7 +2214,7 @@ def testfunc(n):
22142214
uops = get_opnames(ex)
22152215
self.assertIn("_CALL_BUILTIN_O", uops)
22162216
self.assertIn("_POP_TOP_NOP", uops)
2217-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 4)
2217+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 4)
22182218

22192219
def test_call_method_descriptor_o(self):
22202220
def testfunc(n):
@@ -2231,7 +2231,7 @@ def testfunc(n):
22312231
uops = get_opnames(ex)
22322232
self.assertIn("_CALL_METHOD_DESCRIPTOR_O", uops)
22332233
self.assertIn("_POP_TOP_NOP", uops)
2234-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 4)
2234+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 4)
22352235

22362236
def test_get_len_with_const_tuple(self):
22372237
def testfunc(n):
@@ -2558,7 +2558,7 @@ def testfunc(n):
25582558
uops = get_opnames(ex)
25592559
self.assertIn("_POP_TOP_NOP", uops)
25602560
self.assertIn("_PUSH_FRAME", uops)
2561-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 1)
2561+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 1)
25622562

25632563
def test_store_fast_refcount_elimination_when_uninitialized(self):
25642564
def foo():
@@ -2578,7 +2578,7 @@ def testfunc(n):
25782578
uops = get_opnames(ex)
25792579
self.assertIn("_POP_TOP_NOP", uops)
25802580
self.assertIn("_PUSH_FRAME", uops)
2581-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 1)
2581+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 1)
25822582

25832583

25842584
def test_float_op_refcount_elimination(self):
@@ -2611,7 +2611,7 @@ class C():
26112611
uops = get_opnames(ex)
26122612

26132613
self.assertIn("_LOAD_ATTR_INSTANCE_VALUE", uops)
2614-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
2614+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
26152615
self.assertIn("_POP_TOP_NOP", uops)
26162616

26172617
def test_load_attr_with_hint(self):
@@ -2632,7 +2632,7 @@ class C:
26322632
uops = get_opnames(ex)
26332633

26342634
self.assertIn("_LOAD_ATTR_WITH_HINT", uops)
2635-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
2635+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
26362636
self.assertIn("_POP_TOP_NOP", uops)
26372637

26382638
def test_load_addr_slot(self):
@@ -2651,7 +2651,7 @@ class C:
26512651
uops = get_opnames(ex)
26522652

26532653
self.assertIn("_LOAD_ATTR_SLOT", uops)
2654-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
2654+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
26552655
self.assertIn("_POP_TOP_NOP", uops)
26562656

26572657
def test_int_add_op_refcount_elimination(self):
@@ -2667,7 +2667,7 @@ def testfunc(n):
26672667
uops = get_opnames(ex)
26682668
self.assertIn("_BINARY_OP_ADD_INT", uops)
26692669
self.assertIn("_POP_TOP_NOP", uops)
2670-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
2670+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
26712671

26722672
def test_int_sub_op_refcount_elimination(self):
26732673
def testfunc(n):
@@ -2682,7 +2682,7 @@ def testfunc(n):
26822682
uops = get_opnames(ex)
26832683
self.assertIn("_BINARY_OP_SUBTRACT_INT", uops)
26842684
self.assertIn("_POP_TOP_NOP", uops)
2685-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
2685+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
26862686

26872687
def test_int_mul_op_refcount_elimination(self):
26882688
def testfunc(n):
@@ -2697,7 +2697,7 @@ def testfunc(n):
26972697
uops = get_opnames(ex)
26982698
self.assertIn("_BINARY_OP_MULTIPLY_INT", uops)
26992699
self.assertIn("_POP_TOP_NOP", uops)
2700-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
2700+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
27012701

27022702
def test_int_cmp_op_refcount_elimination(self):
27032703
def testfunc(n):
@@ -2712,7 +2712,7 @@ def testfunc(n):
27122712
uops = get_opnames(ex)
27132713
self.assertIn("_COMPARE_OP_INT", uops)
27142714
self.assertIn("_POP_TOP_NOP", uops)
2715-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
2715+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
27162716

27172717
def test_float_cmp_op_refcount_elimination(self):
27182718
def testfunc(n):
@@ -2727,7 +2727,7 @@ def testfunc(n):
27272727
uops = get_opnames(ex)
27282728
self.assertIn("_COMPARE_OP_FLOAT", uops)
27292729
self.assertIn("_POP_TOP_NOP", uops)
2730-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
2730+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
27312731

27322732
def test_str_cmp_op_refcount_elimination(self):
27332733
def testfunc(n):
@@ -2742,7 +2742,7 @@ def testfunc(n):
27422742
uops = get_opnames(ex)
27432743
self.assertIn("_COMPARE_OP_STR", uops)
27442744
self.assertIn("_POP_TOP_NOP", uops)
2745-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
2745+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
27462746

27472747
def test_unicode_add_op_refcount_elimination(self):
27482748
def testfunc(n):
@@ -2758,7 +2758,7 @@ def testfunc(n):
27582758
uops = get_opnames(ex)
27592759
self.assertIn("_BINARY_OP_ADD_UNICODE", uops)
27602760
self.assertIn("_POP_TOP_NOP", uops)
2761-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
2761+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
27622762

27632763
def test_remove_guard_for_slice_list(self):
27642764
def f(n):
@@ -2817,7 +2817,7 @@ class C:
28172817
uops = get_opnames(ex)
28182818

28192819
self.assertIn("_STORE_ATTR_INSTANCE_VALUE", uops)
2820-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 1)
2820+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 1)
28212821
self.assertIn("_POP_TOP_NOP", uops)
28222822

28232823
def test_store_attr_with_hint(self):
@@ -2837,7 +2837,7 @@ class C:
28372837
uops = get_opnames(ex)
28382838

28392839
self.assertIn("_STORE_ATTR_WITH_HINT", uops)
2840-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 1)
2840+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 1)
28412841
self.assertIn("_POP_TOP_NOP", uops)
28422842

28432843
def test_store_subscr_int(self):
@@ -2855,7 +2855,7 @@ def testfunc(n):
28552855
self.assertIsNotNone(ex)
28562856
uops = get_opnames(ex)
28572857
self.assertIn("_STORE_SUBSCR_LIST_INT", uops)
2858-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 1)
2858+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 1)
28592859
self.assertNotIn("_POP_TOP_INT", uops)
28602860
self.assertIn("_POP_TOP_NOP", uops)
28612861

@@ -2892,7 +2892,7 @@ def testfunc(n):
28922892
self.assertIsNotNone(ex)
28932893
uops = get_opnames(ex)
28942894
self.assertIn("_STORE_SUBSCR_DICT", uops)
2895-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 1)
2895+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 1)
28962896
self.assertIn("_POP_TOP_NOP", uops)
28972897

28982898
def test_attr_promotion_failure(self):
@@ -3226,7 +3226,7 @@ def testfunc(n):
32263226
assert "_LOAD_CONST_INLINE_BORROW" in uops
32273227
assert "_POP_TOP_NOP" in uops
32283228
pop_top_count = [opname for opname in ex if opname == "_POP_TOP" ]
3229-
len(pop_top_count) <= 2
3229+
assert len(pop_top_count) <= 2
32303230
"""), PYTHON_JIT="1")
32313231
self.assertEqual(result[0].rc, 0, result)
32323232

@@ -3257,8 +3257,8 @@ def testfunc(n):
32573257
uops = get_opnames(ex)
32583258

32593259
self.assertIn("_BINARY_OP_SUBSCR_LIST_INT", uops)
3260-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
3261-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP_INT")), 1)
3260+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
3261+
self.assertLessEqual(count_ops(ex, "_POP_TOP_INT"), 1)
32623262
self.assertIn("_POP_TOP_NOP", uops)
32633263

32643264
def test_binary_subscr_tuple_int(self):
@@ -3276,8 +3276,8 @@ def testfunc(n):
32763276
uops = get_opnames(ex)
32773277

32783278
self.assertIn("_BINARY_OP_SUBSCR_TUPLE_INT", uops)
3279-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 3)
3280-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP_INT")), 1)
3279+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 3)
3280+
self.assertLessEqual(count_ops(ex, "_POP_TOP_INT"), 1)
32813281
self.assertIn("_POP_TOP_NOP", uops)
32823282

32833283
def test_is_op(self):
@@ -3295,7 +3295,7 @@ def test_is_false(n):
32953295

32963296
self.assertIn("_IS_OP", uops)
32973297
self.assertIn("_POP_TOP_NOP", uops)
3298-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
3298+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
32993299

33003300

33013301
def test_is_true(n):
@@ -3311,7 +3311,7 @@ def test_is_true(n):
33113311

33123312
self.assertIn("_IS_OP", uops)
33133313
self.assertIn("_POP_TOP_NOP", uops)
3314-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
3314+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
33153315

33163316

33173317
def test_is_not(n):
@@ -3328,7 +3328,7 @@ def test_is_not(n):
33283328

33293329
self.assertIn("_IS_OP", uops)
33303330
self.assertIn("_POP_TOP_NOP", uops)
3331-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
3331+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
33323332

33333333

33343334
def test_is_none(n):
@@ -3343,7 +3343,7 @@ def test_is_none(n):
33433343

33443344
self.assertIn("_IS_OP", uops)
33453345
self.assertIn("_POP_TOP_NOP", uops)
3346-
self.assertLessEqual(len(matching_opnames(ex, "_POP_TOP")), 2)
3346+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
33473347

33483348
def test_143026(self):
33493349
# https://github.com/python/cpython/issues/143026

0 commit comments

Comments
 (0)