Skip to content

Commit 50b3f20

Browse files
miss-islingtonRémi Lapeyre
andauthored
bpo-36969: Make PDB args command display keyword only arguments (pythonGH-13452)
(cherry picked from commit bf457c7) Co-authored-by: Rémi Lapeyre <[email protected]>
1 parent 3887932 commit 50b3f20

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

Lib/pdb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,9 +1133,9 @@ def do_args(self, arg):
11331133
"""
11341134
co = self.curframe.f_code
11351135
dict = self.curframe_locals
1136-
n = co.co_argcount
1137-
if co.co_flags & 4: n = n+1
1138-
if co.co_flags & 8: n = n+1
1136+
n = co.co_argcount + co.co_kwonlyargcount
1137+
if co.co_flags & inspect.CO_VARARGS: n = n+1
1138+
if co.co_flags & inspect.CO_VARKEYWORDS: n = n+1
11391139
for i in range(n):
11401140
name = co.co_varnames[i]
11411141
if name in dict:

Lib/test/test_pdb.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ def test_pdb_basic_commands():
7777
... print('...')
7878
... return foo.upper()
7979
80+
>>> def test_function3(arg=None, *, kwonly=None):
81+
... pass
82+
8083
>>> def test_function():
8184
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
8285
... ret = test_function_2('baz')
86+
... test_function3(kwonly=True)
8387
... print(ret)
8488
8589
>>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
@@ -97,10 +101,13 @@ def test_pdb_basic_commands():
97101
... 'jump 8', # jump over second for loop
98102
... 'return', # return out of function
99103
... 'retval', # display return value
104+
... 'next', # step to test_function3()
105+
... 'step', # stepping into test_function3()
106+
... 'args', # display function args
100107
... 'continue',
101108
... ]):
102109
... test_function()
103-
> <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
110+
> <doctest test.test_pdb.test_pdb_basic_commands[2]>(3)test_function()
104111
-> ret = test_function_2('baz')
105112
(Pdb) step
106113
--Call--
@@ -123,14 +130,14 @@ def test_pdb_basic_commands():
123130
[EOF]
124131
(Pdb) bt
125132
...
126-
<doctest test.test_pdb.test_pdb_basic_commands[2]>(18)<module>()
133+
<doctest test.test_pdb.test_pdb_basic_commands[3]>(21)<module>()
127134
-> test_function()
128-
<doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
135+
<doctest test.test_pdb.test_pdb_basic_commands[2]>(3)test_function()
129136
-> ret = test_function_2('baz')
130137
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
131138
-> def test_function_2(foo, bar='default'):
132139
(Pdb) up
133-
> <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
140+
> <doctest test.test_pdb.test_pdb_basic_commands[2]>(3)test_function()
134141
-> ret = test_function_2('baz')
135142
(Pdb) down
136143
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
@@ -168,6 +175,16 @@ def test_pdb_basic_commands():
168175
-> return foo.upper()
169176
(Pdb) retval
170177
'BAZ'
178+
(Pdb) next
179+
> <doctest test.test_pdb.test_pdb_basic_commands[2]>(4)test_function()
180+
-> test_function3(kwonly=True)
181+
(Pdb) step
182+
--Call--
183+
> <doctest test.test_pdb.test_pdb_basic_commands[1]>(1)test_function3()
184+
-> def test_function3(arg=None, *, kwonly=None):
185+
(Pdb) args
186+
arg = None
187+
kwonly = True
171188
(Pdb) continue
172189
BAZ
173190
"""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PDB command `args` now display keyword only arguments. Patch contributed by
2+
Rémi Lapeyre.

0 commit comments

Comments
 (0)