Skip to content
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
6 changes: 3 additions & 3 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,9 +1132,9 @@ def do_args(self, arg):
"""
co = self.curframe.f_code
dict = self.curframe_locals
n = co.co_argcount
if co.co_flags & 4: n = n+1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for removing these evil magic numbers!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely the improvement Python needed ^^

if co.co_flags & 8: n = n+1
n = co.co_argcount + co.co_kwonlyargcount

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to add co.co_posonlyargcount to handle PEP570 (check the issue). Although this will difficult backporting, so maybe you want this to be done in a separate PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank @pablogsal, it may be simple to do so in a separate PR I think.

if co.co_flags & inspect.CO_VARARGS: n = n+1
if co.co_flags & inspect.CO_VARKEYWORDS: n = n+1
for i in range(n):
name = co.co_varnames[i]
if name in dict:
Expand Down
25 changes: 21 additions & 4 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ def test_pdb_basic_commands():
... print('...')
... return foo.upper()

>>> def test_function3(arg=None, *, kwonly=None):
... pass

>>> def test_function():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... ret = test_function_2('baz')
... test_function3(kwonly=True)
... print(ret)

>>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
Expand All @@ -97,10 +101,13 @@ def test_pdb_basic_commands():
... 'jump 8', # jump over second for loop
... 'return', # return out of function
... 'retval', # display return value
... 'next', # step to test_function3()
... 'step', # stepping into test_function3()
... 'args', # display function args
... 'continue',
... ]):
... test_function()
> <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
> <doctest test.test_pdb.test_pdb_basic_commands[2]>(3)test_function()
-> ret = test_function_2('baz')
(Pdb) step
--Call--
Expand All @@ -123,14 +130,14 @@ def test_pdb_basic_commands():
[EOF]
(Pdb) bt
...
<doctest test.test_pdb.test_pdb_basic_commands[2]>(18)<module>()
<doctest test.test_pdb.test_pdb_basic_commands[3]>(21)<module>()
-> test_function()
<doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
<doctest test.test_pdb.test_pdb_basic_commands[2]>(3)test_function()
-> ret = test_function_2('baz')
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
-> def test_function_2(foo, bar='default'):
(Pdb) up
> <doctest test.test_pdb.test_pdb_basic_commands[1]>(3)test_function()
> <doctest test.test_pdb.test_pdb_basic_commands[2]>(3)test_function()
-> ret = test_function_2('baz')
(Pdb) down
> <doctest test.test_pdb.test_pdb_basic_commands[0]>(1)test_function_2()
Expand Down Expand Up @@ -168,6 +175,16 @@ def test_pdb_basic_commands():
-> return foo.upper()
(Pdb) retval
'BAZ'
(Pdb) next
> <doctest test.test_pdb.test_pdb_basic_commands[2]>(4)test_function()
-> test_function3(kwonly=True)
(Pdb) step
--Call--
> <doctest test.test_pdb.test_pdb_basic_commands[1]>(1)test_function3()
-> def test_function3(arg=None, *, kwonly=None):
(Pdb) args
arg = None
kwonly = True
(Pdb) continue
BAZ
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PDB command `args` now display keyword only arguments. Patch contributed by
Rémi Lapeyre.