aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test
diff options
context:
space:
mode:
authorNadeshiko Manju <me@manjusaka.me>2025-05-21 06:02:50 +0800
committerGitHub <noreply@github.com>2025-05-20 18:02:50 -0400
commite1c0c451a2ff815fc817e71ec15c37bff9cb84d0 (patch)
treed3341c74525bfd9fe14f1625a0f65f59ac94519d /Lib/test
parente4fbfb12889013fd52565cd2598a366754cb677b (diff)
downloadcpython-e1c0c451a2ff815fc817e71ec15c37bff9cb84d0.tar.gz
cpython-e1c0c451a2ff815fc817e71ec15c37bff9cb84d0.zip
GH-131798: Narrow the return type of _GET_LEN to int (GH-133345)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_capi/test_opt.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py
index f7a4200e1ee..50c4f19a1ab 100644
--- a/Lib/test/test_capi/test_opt.py
+++ b/Lib/test/test_capi/test_opt.py
@@ -1925,6 +1925,50 @@ class TestUopsOptimization(unittest.TestCase):
self.assertNotIn("_GUARD_NOS_INT", uops)
self.assertNotIn("_GUARD_TOS_INT", uops)
+ def test_get_len_with_const_tuple(self):
+ def testfunc(n):
+ x = 0.0
+ for _ in range(n):
+ match (1, 2, 3, 4):
+ case [_, _, _, _]:
+ x += 1.0
+ return x
+ res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
+ self.assertEqual(int(res), TIER2_THRESHOLD)
+ uops = get_opnames(ex)
+ self.assertNotIn("_GUARD_NOS_INT", uops)
+ self.assertNotIn("_GET_LEN", uops)
+ self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
+
+ def test_get_len_with_non_const_tuple(self):
+ def testfunc(n):
+ x = 0.0
+ for _ in range(n):
+ match object(), object():
+ case [_, _]:
+ x += 1.0
+ return x
+ res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
+ self.assertEqual(int(res), TIER2_THRESHOLD)
+ uops = get_opnames(ex)
+ self.assertNotIn("_GUARD_NOS_INT", uops)
+ self.assertNotIn("_GET_LEN", uops)
+ self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
+
+ def test_get_len_with_non_tuple(self):
+ def testfunc(n):
+ x = 0.0
+ for _ in range(n):
+ match [1, 2, 3, 4]:
+ case [_, _, _, _]:
+ x += 1.0
+ return x
+ res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
+ self.assertEqual(int(res), TIER2_THRESHOLD)
+ uops = get_opnames(ex)
+ self.assertNotIn("_GUARD_NOS_INT", uops)
+ self.assertIn("_GET_LEN", uops)
+
def test_binary_op_subscr_tuple_int(self):
def testfunc(n):
x = 0