summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2024-12-19 02:08:17 (GMT)
committerGitHub <noreply@github.com>2024-12-19 02:08:17 (GMT)
commit48c70b8f7dfd00a018abbac50ea987f54fa4db51 (patch)
treecb845fc352998aa71d0a490c346b4c4145b1a6af /Lib/test
parentf802c8bf872ab882d3056675acc79c950fe5b93c (diff)
downloadcpython-48c70b8f7dfd00a018abbac50ea987f54fa4db51.zip
cpython-48c70b8f7dfd00a018abbac50ea987f54fa4db51.tar.gz
cpython-48c70b8f7dfd00a018abbac50ea987f54fa4db51.tar.bz2
gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build (gh-127737)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_opcache.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_opcache.py b/Lib/test/test_opcache.py
index 0a7557a..94709e2 100644
--- a/Lib/test/test_opcache.py
+++ b/Lib/test/test_opcache.py
@@ -1069,7 +1069,7 @@ class TestRacesDoNotCrash(TestBase):
opname = "STORE_SUBSCR_LIST_INT"
self.assert_races_do_not_crash(opname, get_items, read, write)
- @requires_specialization
+ @requires_specialization_ft
def test_unpack_sequence_list(self):
def get_items():
items = []
@@ -1245,6 +1245,14 @@ class TestInstanceDict(unittest.TestCase):
f(test_obj, 1)
self.assertEqual(test_obj.b, 0)
+# gh-127274: BINARY_SUBSCR_GETITEM will only cache __getitem__ methods that
+# are deferred. We only defer functions defined at the top-level.
+class CGetItem:
+ def __init__(self, val):
+ self.val = val
+ def __getitem__(self, item):
+ return self.val
+
class TestSpecializer(TestBase):
@@ -1520,6 +1528,15 @@ class TestSpecializer(TestBase):
self.assert_specialized(binary_subscr_str_int, "BINARY_SUBSCR_STR_INT")
self.assert_no_opcode(binary_subscr_str_int, "BINARY_SUBSCR")
+ def binary_subscr_getitems():
+ items = [CGetItem(i) for i in range(100)]
+ for i in range(100):
+ self.assertEqual(items[i][i], i)
+
+ binary_subscr_getitems()
+ self.assert_specialized(binary_subscr_getitems, "BINARY_SUBSCR_GETITEM")
+ self.assert_no_opcode(binary_subscr_getitems, "BINARY_SUBSCR")
+
if __name__ == "__main__":
unittest.main()