From f965f0a85a90af1184255ef31b4dea76c438d64c Mon Sep 17 00:00:00 2001 From: chilaxan Date: Fri, 2 Dec 2022 00:41:57 -0500 Subject: [PATCH 1/5] remove hardcoded check that op is LOAD_CONST 3.11 adds a new opcode KW_NAMES that has an entry in co_consts, however the hardcoded check here causes dis to not grab the constant --- Lib/dis.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/dis.py b/Lib/dis.py index 6a7fcb8a1a0071..f2cb3d34df3aab 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -368,9 +368,8 @@ def _get_const_value(op, arg, co_consts): assert op in hasconst argval = UNKNOWN - if op == LOAD_CONST or op == RETURN_CONST: - if co_consts is not None: - argval = co_consts[arg] + if co_consts is not None: + argval = co_consts[arg] return argval def _get_const_info(op, arg, co_consts): From daba632a887b71798161d29ccb7005919062a3a5 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Tue, 25 Apr 2023 15:07:57 -0700 Subject: [PATCH 2/5] Add auxiliary fcns, expected dis output, and text fcns --- Lib/test/test_dis.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 2d5c73c9adc920..761f010b9c775c 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -227,6 +227,24 @@ def bug42562(): JUMP_FORWARD -4 (to 0) """ +def func_w_kwargs(a, b, **c): + pass + +def wrap_func_w_kwargs(): + func_w_kwargs(1, 2, c=5) + +dis_kw_names = """\ +%3d 0 RESUME 0 + 2 LOAD_GLOBAL 1 (NULL + f) + 12 LOAD_CONST 1 (1) + 14 LOAD_CONST 2 (2) + 16 LOAD_CONST 3 (5) + 18 KW_NAMES 4 (('c',)) + 20 CALL 3 + 28 POP_TOP + 30 RETURN_CONST 0 (None) +""" % (wrap_func_w_kwargs.__code__.co_firstlineno) + _BIG_LINENO_FORMAT = """\ 1 RESUME 0 @@ -911,6 +929,10 @@ def test_bug_46724(self): # Test that negative operargs are handled properly self.do_disassembly_test(bug46724, dis_bug46724) + def test_kw_names(self): + # Test that information is populated for KW_NAMES + self.do_disassembly_test(wrap_func_w_kwargs, dis_kw_names) + def test_big_linenos(self): def func(count): namespace = {} From 6dee194096ad63f1888720ef0d8ad7d5b2c64ab1 Mon Sep 17 00:00:00 2001 From: jkchandalia Date: Tue, 25 Apr 2023 15:30:04 -0700 Subject: [PATCH 3/5] Update dis output string for test case --- Lib/test/test_dis.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 761f010b9c775c..7814b6f7778f2c 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -234,16 +234,18 @@ def wrap_func_w_kwargs(): func_w_kwargs(1, 2, c=5) dis_kw_names = """\ -%3d 0 RESUME 0 - 2 LOAD_GLOBAL 1 (NULL + f) - 12 LOAD_CONST 1 (1) - 14 LOAD_CONST 2 (2) - 16 LOAD_CONST 3 (5) - 18 KW_NAMES 4 (('c',)) - 20 CALL 3 - 28 POP_TOP - 30 RETURN_CONST 0 (None) -""" % (wrap_func_w_kwargs.__code__.co_firstlineno) +%3d RESUME 0 + +%3d LOAD_GLOBAL 1 (NULL + func_w_kwargs) + LOAD_CONST 1 (1) + LOAD_CONST 2 (2) + LOAD_CONST 3 (5) + KW_NAMES 4 (('c',)) + CALL 3 + POP_TOP + RETURN_CONST 0 (None) +""" % (wrap_func_w_kwargs.__code__.co_firstlineno, + wrap_func_w_kwargs.__code__.co_firstlineno + 1) _BIG_LINENO_FORMAT = """\ 1 RESUME 0 From fb6bf1da915c24b8ec03f4930e62dee780bd818f Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Tue, 25 Apr 2023 23:46:04 +0100 Subject: [PATCH 4/5] reword comment --- Lib/test/test_dis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 7814b6f7778f2c..3ba13a22ff880c 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -932,7 +932,7 @@ def test_bug_46724(self): self.do_disassembly_test(bug46724, dis_bug46724) def test_kw_names(self): - # Test that information is populated for KW_NAMES + # Test that value is displayed for KW_NAMES self.do_disassembly_test(wrap_func_w_kwargs, dis_kw_names) def test_big_linenos(self): From bb448e1bb889d2b7f20d279b2062f0071339e81c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 25 Apr 2023 22:59:07 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-04-25-22-59-06.gh-issue-99944.pst8iT.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-04-25-22-59-06.gh-issue-99944.pst8iT.rst diff --git a/Misc/NEWS.d/next/Library/2023-04-25-22-59-06.gh-issue-99944.pst8iT.rst b/Misc/NEWS.d/next/Library/2023-04-25-22-59-06.gh-issue-99944.pst8iT.rst new file mode 100644 index 00000000000000..80238a65e32a41 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-04-25-22-59-06.gh-issue-99944.pst8iT.rst @@ -0,0 +1 @@ +Make :mod:`dis` display the value of oparg of :opcode:`KW_NAMES`.