From 115a7090db19f57251240b40a546894dadc13177 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 26 Aug 2024 19:36:27 +0300 Subject: [PATCH 1/2] gh-123340: Show string value of `IS_OP` oparg in `dis` --- Lib/dis.py | 3 +++ Lib/test/test_dis.py | 9 +++++++++ .../2024-08-26-19-36-00.gh-issue-123340.mQKI1H.rst | 1 + 3 files changed, 13 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-08-26-19-36-00.gh-issue-123340.mQKI1H.rst diff --git a/Lib/dis.py b/Lib/dis.py index 077c4035ca6511..bdac296e9c7a25 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -51,6 +51,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'] CACHE = opmap["CACHE"] @@ -629,6 +630,8 @@ def get_argval_argrepr(self, op, arg, offset): 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): diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index db69bc7ccdc205..ab0fcee747dbf9 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -2028,6 +2028,15 @@ def f(x, y, z): 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 index 00000000000000..bbf1b9d337ead0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-08-26-19-36-00.gh-issue-123340.mQKI1H.rst @@ -0,0 +1 @@ +Show string value of IS_OP oparg in :mod:`dis` output. From 6a99b5bec7a13a2b0defc3a72adf63125d8ea5f5 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 26 Aug 2024 19:41:25 +0300 Subject: [PATCH 2/2] Address review --- .../next/Library/2024-08-26-19-36-00.gh-issue-123340.mQKI1H.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index bbf1b9d337ead0..8a462b2300466e 100644 --- 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 @@ -1 +1 @@ -Show string value of IS_OP oparg in :mod:`dis` output. +Show string value of :opcode:`IS_OP` oparg in :mod:`dis` output.