Skip to content

Commit fd474b8

Browse files
committed
gh-128891: add specialized opcodes to opcode.opname
1 parent 8d8b854 commit fd474b8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Lib/opcode.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
EXTENDED_ARG = opmap['EXTENDED_ARG']
1818

1919
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
20-
for op, i in opmap.items():
21-
opname[i] = op
20+
for m in (opmap, _specialized_opmap):
21+
for op, i in m.items():
22+
opname[i] = op
2223

2324
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
2425

Lib/test/test__opcode.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ def test_is_valid(self):
3838
opcodes = [dis.opmap[opname] for opname in names]
3939
self.check_bool_function_result(_opcode.is_valid, opcodes, True)
4040

41+
def test_opmaps(self):
42+
def check_roundtrip(name, map):
43+
return self.assertEqual(opcode.opname[map[name]], name)
44+
45+
check_roundtrip('BINARY_OP', opcode.opmap)
46+
check_roundtrip('BINARY_OP_ADD_INT', opcode._specialized_opmap)
47+
4148
def test_oplists(self):
4249
def check_function(self, func, expected):
4350
for op in [-10, 520]:

0 commit comments

Comments
 (0)