Skip to content

Commit d45225b

Browse files
GH-99944: Make dis display the value of oparg of KW_NAMES (#103856)
Co-authored-by: chilaxan <[email protected]>
1 parent 1461a22 commit d45225b

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

Lib/dis.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,8 @@ def _get_const_value(op, arg, co_consts):
369369
assert op in hasconst
370370

371371
argval = UNKNOWN
372-
if op == LOAD_CONST or op == RETURN_CONST:
373-
if co_consts is not None:
374-
argval = co_consts[arg]
372+
if co_consts is not None:
373+
argval = co_consts[arg]
375374
return argval
376375

377376
def _get_const_info(op, arg, co_consts):

Lib/test/test_dis.py

+24
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,26 @@ def bug42562():
227227
JUMP_FORWARD -4 (to 0)
228228
"""
229229

230+
def func_w_kwargs(a, b, **c):
231+
pass
232+
233+
def wrap_func_w_kwargs():
234+
func_w_kwargs(1, 2, c=5)
235+
236+
dis_kw_names = """\
237+
%3d RESUME 0
238+
239+
%3d LOAD_GLOBAL 1 (NULL + func_w_kwargs)
240+
LOAD_CONST 1 (1)
241+
LOAD_CONST 2 (2)
242+
LOAD_CONST 3 (5)
243+
KW_NAMES 4 (('c',))
244+
CALL 3
245+
POP_TOP
246+
RETURN_CONST 0 (None)
247+
""" % (wrap_func_w_kwargs.__code__.co_firstlineno,
248+
wrap_func_w_kwargs.__code__.co_firstlineno + 1)
249+
230250
_BIG_LINENO_FORMAT = """\
231251
1 RESUME 0
232252
@@ -911,6 +931,10 @@ def test_bug_46724(self):
911931
# Test that negative operargs are handled properly
912932
self.do_disassembly_test(bug46724, dis_bug46724)
913933

934+
def test_kw_names(self):
935+
# Test that value is displayed for KW_NAMES
936+
self.do_disassembly_test(wrap_func_w_kwargs, dis_kw_names)
937+
914938
def test_big_linenos(self):
915939
def func(count):
916940
namespace = {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make :mod:`dis` display the value of oparg of :opcode:`KW_NAMES`.

0 commit comments

Comments
 (0)