]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123340: Show string value of `IS_OP` oparg in `dis` (#123348)
authorsobolevn <mail@sobolevn.me>
Mon, 26 Aug 2024 18:59:50 +0000 (21:59 +0300)
committerGitHub <noreply@github.com>
Mon, 26 Aug 2024 18:59:50 +0000 (21:59 +0300)
Lib/dis.py
Lib/test/test_dis.py
Misc/NEWS.d/next/Library/2024-08-26-19-36-00.gh-issue-123340.mQKI1H.rst [new file with mode: 0644]

index 077c4035ca6511729d83549ae57b7557f82ad393..bdac296e9c7a25d7e51acf9e745be47d1f557f24 100644 (file)
@@ -51,6 +51,7 @@ LOAD_SPECIAL = opmap['LOAD_SPECIAL']
 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']
 
 CACHE = opmap["CACHE"]
 
@@ -629,6 +630,8 @@ class ArgResolver:
                     argrepr = repr(obj)
             elif deop == LOAD_SPECIAL:
                 argrepr = _special_method_names[arg]
+            elif deop == IS_OP:
+                argrepr = 'is not' if argval else 'is'
         return argval, argrepr
 
 def get_instructions(x, *, first_line=None, show_caches=None, adaptive=False):
index db69bc7ccdc205fe292cfc41e8016b56c209b162..ab0fcee747dbf997e479c00df3dbed49bd5de3d0 100644 (file)
@@ -2028,6 +2028,15 @@ class InstructionTests(InstructionTestCase):
         dis.dis(f.__code__, file=output, show_caches=True)
         self.assertIn("L1:", output.getvalue())
 
+    def test_is_op_format(self):
+        output = io.StringIO()
+        dis.dis("a is b", file=output, show_caches=True)
+        self.assertIn("IS_OP                    0 (is)", output.getvalue())
+
+        output = io.StringIO()
+        dis.dis("a is not b", file=output, show_caches=True)
+        self.assertIn("IS_OP                    1 (is not)", 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-26-19-36-00.gh-issue-123340.mQKI1H.rst b/Misc/NEWS.d/next/Library/2024-08-26-19-36-00.gh-issue-123340.mQKI1H.rst
new file mode 100644 (file)
index 0000000..8a462b2
--- /dev/null
@@ -0,0 +1 @@
+Show string value of :opcode:`IS_OP` oparg in :mod:`dis` output.