From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 20 May 2019 22:34:23 +0000 (-0700) Subject: bpo-36969: Make PDB args command display keyword only arguments (GH-13452) X-Git-Tag: v3.7.4rc1~124 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=50b3f205d82d88eec69f18a0ad4bb2440ba73501;p=thirdparty%2FPython%2Fcpython.git bpo-36969: Make PDB args command display keyword only arguments (GH-13452) (cherry picked from commit bf457c7d8224179a023957876e757f2a7ffc3d9d) Co-authored-by: Rémi Lapeyre --- diff --git a/Lib/pdb.py b/Lib/pdb.py index bf3219af3985..59b23dfc8bea 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1133,9 +1133,9 @@ class Pdb(bdb.Bdb, cmd.Cmd): """ co = self.curframe.f_code dict = self.curframe_locals - n = co.co_argcount - if co.co_flags & 4: n = n+1 - if co.co_flags & 8: n = n+1 + n = co.co_argcount + co.co_kwonlyargcount + 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: diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index c2c4ca248d1b..de6c651b370a 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -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 @@ -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() - > (3)test_function() + > (3)test_function() -> ret = test_function_2('baz') (Pdb) step --Call-- @@ -123,14 +130,14 @@ def test_pdb_basic_commands(): [EOF] (Pdb) bt ... - (18)() + (21)() -> test_function() - (3)test_function() + (3)test_function() -> ret = test_function_2('baz') > (1)test_function_2() -> def test_function_2(foo, bar='default'): (Pdb) up - > (3)test_function() + > (3)test_function() -> ret = test_function_2('baz') (Pdb) down > (1)test_function_2() @@ -168,6 +175,16 @@ def test_pdb_basic_commands(): -> return foo.upper() (Pdb) retval 'BAZ' + (Pdb) next + > (4)test_function() + -> test_function3(kwonly=True) + (Pdb) step + --Call-- + > (1)test_function3() + -> def test_function3(arg=None, *, kwonly=None): + (Pdb) args + arg = None + kwonly = True (Pdb) continue BAZ """ diff --git a/Misc/NEWS.d/next/Library/2019-05-20-23-31-20.bpo-36969.JkZORP.rst b/Misc/NEWS.d/next/Library/2019-05-20-23-31-20.bpo-36969.JkZORP.rst new file mode 100644 index 000000000000..9253ab92f1fb --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-05-20-23-31-20.bpo-36969.JkZORP.rst @@ -0,0 +1,2 @@ +PDB command `args` now display keyword only arguments. Patch contributed by +Rémi Lapeyre.