Skip to content

GH-99944: Make dis display the value of oparg of KW_NAMES #103856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
24 changes: 24 additions & 0 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,26 @@ 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 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

Expand Down Expand Up @@ -911,6 +931,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 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 = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make :mod:`dis` display the value of oparg of :opcode:`KW_NAMES`.