https://github.com/python/cpython/commit/6a7765b9fad8bf67e2c118b637a516c5e6c42349
commit: 6a7765b9fad8bf67e2c118b637a516c5e6c42349
branch: main
author: Alexandr Mitin <[email protected]>
committer: sobolevn <[email protected]>
date: 2024-08-28T09:15:34+03:00
summary:

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>

files:
A Misc/NEWS.d/next/Library/2024-08-27-12-11-00.gh-issue-123363.gKuJp6.rst
M Lib/dis.py
M Lib/test/test_dis.py

diff --git a/Lib/dis.py b/Lib/dis.py
index bdac296e9c7a25..f8832b30497822 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -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"]
 
@@ -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):
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index ab0fcee747dbf9..bccd2182412577 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -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 (in)", output.getvalue())
+
+        output = io.StringIO()
+        dis.dis("a not in b", file=output, show_caches=True)
+        self.assertIn("CONTAINS_OP              1 (not in)", output.getvalue())
+
     def test_baseopname_and_baseopcode(self):
         # Standard instructions
         for name, code in dis.opmap.items():
diff --git 
a/Misc/NEWS.d/next/Library/2024-08-27-12-11-00.gh-issue-123363.gKuJp6.rst 
b/Misc/NEWS.d/next/Library/2024-08-27-12-11-00.gh-issue-123363.gKuJp6.rst
new file mode 100644
index 00000000000000..c1f92c4d54dbb0
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-08-27-12-11-00.gh-issue-123363.gKuJp6.rst
@@ -0,0 +1,2 @@
+Show string value of :opcode:`CONTAINS_OP` oparg in :mod:`dis` output.
+Patch by Alexandr153.

_______________________________________________
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]

Reply via email to