Skip to content

Commit 6a7765b

Browse files
gh-123363: Show string value of CONTAINS_OP oparg in dis (#123387)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent 2231286 commit 6a7765b

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Lib/dis.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
STORE_FAST_LOAD_FAST = opmap['STORE_FAST_LOAD_FAST']
5353
STORE_FAST_STORE_FAST = opmap['STORE_FAST_STORE_FAST']
5454
IS_OP = opmap['IS_OP']
55+
CONTAINS_OP = opmap['CONTAINS_OP']
5556

5657
CACHE = opmap["CACHE"]
5758

@@ -632,6 +633,8 @@ def get_argval_argrepr(self, op, arg, offset):
632633
argrepr = _special_method_names[arg]
633634
elif deop == IS_OP:
634635
argrepr = 'is not' if argval else 'is'
636+
elif deop == CONTAINS_OP:
637+
argrepr = 'not in' if argval else 'in'
635638
return argval, argrepr
636639

637640
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
@@ -2037,6 +2037,15 @@ def test_is_op_format(self):
20372037
dis.dis("a is not b", file=output, show_caches=True)
20382038
self.assertIn("IS_OP 1 (is not)", output.getvalue())
20392039

2040+
def test_contains_op_format(self):
2041+
output = io.StringIO()
2042+
dis.dis("a in b", file=output, show_caches=True)
2043+
self.assertIn("CONTAINS_OP 0 (in)", output.getvalue())
2044+
2045+
output = io.StringIO()
2046+
dis.dis("a not in b", file=output, show_caches=True)
2047+
self.assertIn("CONTAINS_OP 1 (not in)", output.getvalue())
2048+
20402049
def test_baseopname_and_baseopcode(self):
20412050
# Standard instructions
20422051
for name, code in dis.opmap.items():
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Show string value of :opcode:`CONTAINS_OP` oparg in :mod:`dis` output.
2+
Patch by Alexandr153.

0 commit comments

Comments
 (0)