summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuhi Chandalia <jkchandalia@gmail.com>2023-04-26 18:00:36 (GMT)
committerGitHub <noreply@github.com>2023-04-26 18:00:36 (GMT)
commitd45225bd66a8123e4a30314c627f2586293ba532 (patch)
tree6be89e3827bc3c46e5389f1728f81ae85b9e060c
parent1461a22f91a3da2b08f6e485a500bed8b193a601 (diff)
downloadcpython-d45225bd66a8123e4a30314c627f2586293ba532.zip
cpython-d45225bd66a8123e4a30314c627f2586293ba532.tar.gz
cpython-d45225bd66a8123e4a30314c627f2586293ba532.tar.bz2
GH-99944: Make dis display the value of oparg of KW_NAMES (#103856)
Co-authored-by: chilaxan <chilaxan@gmail.com>
-rw-r--r--Lib/dis.py5
-rw-r--r--Lib/test/test_dis.py24
-rw-r--r--Misc/NEWS.d/next/Library/2023-04-25-22-59-06.gh-issue-99944.pst8iT.rst1
3 files changed, 27 insertions, 3 deletions
diff --git a/Lib/dis.py b/Lib/dis.py
index 8af84c0..85c1095 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -369,9 +369,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):
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 9796072..bdb541e 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -227,6 +227,26 @@ dis_bug46724 = """\
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 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
@@ -911,6 +931,10 @@ class DisTests(DisTestBase):
# Test that negative operargs are handled properly
self.do_disassembly_test(bug46724, dis_bug46724)
+ def test_kw_names(self):
+ # Test that value is displayed for KW_NAMES
+ self.do_disassembly_test(wrap_func_w_kwargs, dis_kw_names)
+
def test_big_linenos(self):
def func(count):
namespace = {}
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 0000000..80238a6
--- /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`.