Skip to content

Commit 1eed0f9

Browse files
authored
gh-123340: Show string value of IS_OP oparg in dis (#123348)
1 parent 7bd6ebf commit 1eed0f9

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Lib/dis.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
LOAD_FAST_LOAD_FAST = opmap['LOAD_FAST_LOAD_FAST']
5252
STORE_FAST_LOAD_FAST = opmap['STORE_FAST_LOAD_FAST']
5353
STORE_FAST_STORE_FAST = opmap['STORE_FAST_STORE_FAST']
54+
IS_OP = opmap['IS_OP']
5455

5556
CACHE = opmap["CACHE"]
5657

@@ -629,6 +630,8 @@ def get_argval_argrepr(self, op, arg, offset):
629630
argrepr = repr(obj)
630631
elif deop == LOAD_SPECIAL:
631632
argrepr = _special_method_names[arg]
633+
elif deop == IS_OP:
634+
argrepr = 'is not' if argval else 'is'
632635
return argval, argrepr
633636

634637
def get_instructions(x, *, first_line=None, show_caches=None, adaptive=False):

Lib/test/test_dis.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,15 @@ def f(x, y, z):
20282028
dis.dis(f.__code__, file=output, show_caches=True)
20292029
self.assertIn("L1:", output.getvalue())
20302030

2031+
def test_is_op_format(self):
2032+
output = io.StringIO()
2033+
dis.dis("a is b", file=output, show_caches=True)
2034+
self.assertIn("IS_OP 0 (is)", output.getvalue())
2035+
2036+
output = io.StringIO()
2037+
dis.dis("a is not b", file=output, show_caches=True)
2038+
self.assertIn("IS_OP 1 (is not)", output.getvalue())
2039+
20312040
def test_baseopname_and_baseopcode(self):
20322041
# Standard instructions
20332042
for name, code in dis.opmap.items():
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Show string value of :opcode:`IS_OP` oparg in :mod:`dis` output.

0 commit comments

Comments
 (0)