Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-123363: Show string value of CONTAINS_OP oparg in dis #123387

Merged
merged 8 commits into from
Aug 28, 2024
Next Next commit
Show string value of CONTAINS_OP oparg in dis
  • Loading branch information
Alexandr153 committed Aug 27, 2024
commit b8a547577299e690810c4d87bb6628f7e647e960
3 changes: 3 additions & 0 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
STORE_FAST_LOAD_FAST = opmap['STORE_FAST_LOAD_FAST']
STORE_FAST_STORE_FAST = opmap['STORE_FAST_STORE_FAST']
IS_OP = opmap['IS_OP']
CONTAINS_OP = opmap['CONTAINS_OP']

CACHE = opmap["CACHE"]

Expand Down Expand Up @@ -632,6 +633,8 @@ def get_argval_argrepr(self, op, arg, offset):
argrepr = _special_method_names[arg]
elif deop == IS_OP:
argrepr = 'is not' if argval else 'is'
elif deop == CONTAINS_OP:
argrepr = 'not in' if argval else 'in'
return argval, argrepr

def get_instructions(x, *, first_line=None, show_caches=None, adaptive=False):
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,15 @@ def test_is_op_format(self):
dis.dis("a is not b", file=output, show_caches=True)
self.assertIn("IS_OP 1 (is not)", output.getvalue())

def test_contains_op_format(self):
output = io.StringIO()
dis.dis("a in b", file=output, show_caches=True)
self.assertIn("CONTAINS_OP 0 (is)", output.getvalue())

output = io.StringIO()
dis.dis("a not in b", file=output, show_caches=True)
self.assertIn("CONTAINS_OP 1 (is not)", output.getvalue())

def test_baseopname_and_baseopcode(self):
# Standard instructions
for name, code in dis.opmap.items():
Expand Down
Loading