Skip to content

Commit 3d30896

Browse files
committed
Update test
1 parent b803214 commit 3d30896

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

Lib/test/test_capi/test_opt.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,28 @@ class C():
27342734
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
27352735
self.assertIn("_POP_TOP_NOP", uops)
27362736

2737+
def test_load_attr_module(self):
2738+
def testfunc(n):
2739+
import math
2740+
x = 0
2741+
for _ in range(n):
2742+
y = math.pi
2743+
if y:
2744+
x += 1
2745+
return x
2746+
2747+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2748+
self.assertEqual(res, TIER2_THRESHOLD)
2749+
self.assertIsNotNone(ex)
2750+
uops = get_opnames(ex)
2751+
for uop in uops:
2752+
print(uop)
2753+
return
2754+
2755+
self.assertIn("_LOAD_ATTR_MODULE", uops)
2756+
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 3)
2757+
self.assertIn("_POP_TOP_NOP", uops)
2758+
27372759
def test_load_attr_with_hint(self):
27382760
def testfunc(n):
27392761
class C:
@@ -2774,24 +2796,6 @@ class C:
27742796
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
27752797
self.assertIn("_POP_TOP_NOP", uops)
27762798

2777-
def test_load_attr_module(self):
2778-
import platform
2779-
# Use default argument to capture module as local variable
2780-
def testfunc(n, mod=platform):
2781-
x = 0
2782-
for _ in range(n):
2783-
# Access module attribute multiple times
2784-
x = mod.python_version
2785-
return x
2786-
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2787-
self.assertIsNotNone(ex)
2788-
uops = get_opnames(ex)
2789-
2790-
self.assertIn("_LOAD_ATTR_MODULE", uops)
2791-
# _POP_TOP_MODULE should be optimized to _POP_TOP_NOP for borrowed refs
2792-
self.assertIn("_POP_TOP_NOP", uops)
2793-
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
2794-
27952799
def test_int_add_op_refcount_elimination(self):
27962800
def testfunc(n):
27972801
c = 1

0 commit comments

Comments
 (0)