https://github.com/python/cpython/commit/5eee2fe2b05c1a2836184e047fbd4176945cbf10
commit: 5eee2fe2b05c1a2836184e047fbd4176945cbf10
branch: main
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2025-01-15T21:02:32Z
summary:
gh-128891: add specialized opcodes to opcode.opname (#128892)
files:
A Misc/NEWS.d/next/Library/2025-01-15-19-32-23.gh-issue-128891.ojUxKo.rst
M Lib/opcode.py
M Lib/test/test__opcode.py
M Lib/test/test_dis.py
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 974f4d35e2a524..aba66153af1b2e 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -17,8 +17,9 @@
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 d5cf014d40daf8..95e09500df51d0 100644
--- a/Lib/test/test__opcode.py
+++ b/Lib/test/test__opcode.py
@@ -38,6 +38,13 @@ def test_is_valid(self):
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 ed8bd6fa20880b..8afe9653f19f6e 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -999,12 +999,14 @@ def test_boundaries(self):
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 00000000000000..79d845bbab7cfc
--- /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``.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]