summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2025-01-15 21:02:32 (GMT)
committerGitHub <noreply@github.com>2025-01-15 21:02:32 (GMT)
commit5eee2fe2b05c1a2836184e047fbd4176945cbf10 (patch)
treeb4ed5c968ff8db524be528de136258a8d71d01cd
parent256d6d2131541b3ff8f06f42c8157f808fde464c (diff)
downloadcpython-5eee2fe2b05c1a2836184e047fbd4176945cbf10.zip
cpython-5eee2fe2b05c1a2836184e047fbd4176945cbf10.tar.gz
cpython-5eee2fe2b05c1a2836184e047fbd4176945cbf10.tar.bz2
gh-128891: add specialized opcodes to opcode.opname (#128892)
-rw-r--r--Lib/opcode.py5
-rw-r--r--Lib/test/test__opcode.py7
-rw-r--r--Lib/test/test_dis.py6
-rw-r--r--Misc/NEWS.d/next/Library/2025-01-15-19-32-23.gh-issue-128891.ojUxKo.rst1
4 files changed, 15 insertions, 4 deletions
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 974f4d3..aba6615 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -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 = ('<', '<=', '==', '!=', '>', '>=')
diff --git a/Lib/test/test__opcode.py b/Lib/test/test__opcode.py
index d5cf014..95e0950 100644
--- a/Lib/test/test__opcode.py
+++ b/Lib/test/test__opcode.py
@@ -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]:
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index ed8bd6f..8afe965 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -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
index 0000000..79d845b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-15-19-32-23.gh-issue-128891.ojUxKo.rst
@@ -0,0 +1 @@
+Add specialized opcodes to ``opcode.opname``.