]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123363: Show string value of CONTAINS_OP oparg in dis (#123387)
authorAlexandr Mitin <64941904+Alexandr153@users.noreply.github.com>
Wed, 28 Aug 2024 06:15:34 +0000 (12:15 +0600)
committerGitHub <noreply@github.com>
Wed, 28 Aug 2024 06:15:34 +0000 (09:15 +0300)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Lib/dis.py
Lib/test/test_dis.py
Misc/NEWS.d/next/Library/2024-08-27-12-11-00.gh-issue-123363.gKuJp6.rst [new file with mode: 0644]

index bdac296e9c7a25d7e51acf9e745be47d1f557f24..f8832b30497822009ae6100b8c345fda23f63e72 100644 (file)
@@ -52,6 +52,7 @@ LOAD_FAST_LOAD_FAST = opmap['LOAD_FAST_LOAD_FAST']
 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 @@ class ArgResolver:
                 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):
index ab0fcee747dbf997e479c00df3dbed49bd5de3d0..bccd2182412577d57546c4791068bef4bff1be95 100644 (file)
@@ -2037,6 +2037,15 @@ class InstructionTests(InstructionTestCase):
         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 (file)
index 0000000..c1f92c4
--- /dev/null
@@ -0,0 +1,2 @@
+Show string value of :opcode:`CONTAINS_OP` oparg in :mod:`dis` output.
+Patch by Alexandr153.