]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-128891: add specialized opcodes to opcode.opname (#128892)
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Wed, 15 Jan 2025 21:02:32 +0000 (21:02 +0000)
committerGitHub <noreply@github.com>
Wed, 15 Jan 2025 21:02:32 +0000 (21:02 +0000)
Lib/opcode.py
Lib/test/test__opcode.py
Lib/test/test_dis.py
Misc/NEWS.d/next/Library/2025-01-15-19-32-23.gh-issue-128891.ojUxKo.rst [new file with mode: 0644]

index 974f4d35e2a524066a45a6c1e11563b01c99cf9c..aba66153af1b2e7671853f665c06db05ec6f0fbe 100644 (file)
@@ -17,8 +17,9 @@ from _opcode_metadata import (_specializations, _specialized_opmap, opmap,  # no
 EXTENDED_ARG = opmap['EXTENDED_ARG']
 
 opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
-for op, i in opmap.items():
-    opname[i] = op
+for m in (opmap, _specialized_opmap):
+    for op, i in m.items():
+        opname[i] = op
 
 cmp_op = ('<', '<=', '==', '!=', '>', '>=')
 
index d5cf014d40daf8bd77a4732081ac29b2b53a6d58..95e09500df51d06339f636859b8241e5c096fc23 100644 (file)
@@ -38,6 +38,13 @@ class OpListTests(unittest.TestCase):
         opcodes = [dis.opmap[opname] for opname in names]
         self.check_bool_function_result(_opcode.is_valid, opcodes, True)
 
+    def test_opmaps(self):
+        def check_roundtrip(name, map):
+            return self.assertEqual(opcode.opname[map[name]], name)
+
+        check_roundtrip('BINARY_OP', opcode.opmap)
+        check_roundtrip('BINARY_OP_ADD_INT', opcode._specialized_opmap)
+
     def test_oplists(self):
         def check_function(self, func, expected):
             for op in [-10, 520]:
index ed8bd6fa20880bd6dc61ce7e624d0a2e3649290d..8afe9653f19f6ea8a7b061e6cf8dc4f0e047482a 100644 (file)
@@ -999,12 +999,14 @@ class DisTests(DisTestBase):
     def test_widths(self):
         long_opcodes = set(['JUMP_BACKWARD_NO_INTERRUPT',
                             'INSTRUMENTED_CALL_FUNCTION_EX'])
-        for opcode, opname in enumerate(dis.opname):
+        for op, opname in enumerate(dis.opname):
             if opname in long_opcodes or opname.startswith("INSTRUMENTED"):
                 continue
+            if opname in opcode._specialized_opmap:
+                continue
             with self.subTest(opname=opname):
                 width = dis._OPNAME_WIDTH
-                if opcode in dis.hasarg:
+                if op in dis.hasarg:
                     width += 1 + dis._OPARG_WIDTH
                 self.assertLessEqual(len(opname), width)
 
diff --git a/Misc/NEWS.d/next/Library/2025-01-15-19-32-23.gh-issue-128891.ojUxKo.rst b/Misc/NEWS.d/next/Library/2025-01-15-19-32-23.gh-issue-128891.ojUxKo.rst
new file mode 100644 (file)
index 0000000..79d845b
--- /dev/null
@@ -0,0 +1 @@
+Add specialized opcodes to ``opcode.opname``.