From 81918c3c484002afc911edb432157fac28cf4b8e Mon Sep 17 00:00:00 2001 From: Romuald Brunet Date: Thu, 5 Aug 2021 10:04:41 +0200 Subject: [PATCH] bpo-42524: pdb: additional documentation on retval Add documentation on `retval`stating that the return value itself can be accessed via the `__return__` local variable. This is intended to let people know that they can access complex objects using this variable (for example access `__return__.thingy()`) --- Lib/pdb.py | 2 ++ Lib/test/test_pdb.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index d7110074538ace..093bf2234202ce 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1238,6 +1238,8 @@ def do_args(self, arg): def do_retval(self, arg): """retval Print the return value for the last return of a function. + Alternatively, the return value can be accessed with the local + variable ``__return__`` """ if '__return__' in self.curframe_locals: self.message(repr(self.curframe_locals['__return__'])) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 5bb8069021d89d..dffc5d165d6abf 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -107,6 +107,7 @@ def test_pdb_basic_commands(): ... 'jump 8', # jump over second for loop ... 'return', # return out of function ... 'retval', # display return value + ... '__return__', # access the return value ... 'next', # step to test_function3() ... 'step', # stepping into test_function3() ... 'args', # display function args @@ -140,7 +141,7 @@ def test_pdb_basic_commands(): [EOF] (Pdb) bt ... - (25)() + (26)() -> test_function() (3)test_function() -> ret = test_function_2('baz') @@ -185,6 +186,8 @@ def test_pdb_basic_commands(): -> return foo.upper() (Pdb) retval 'BAZ' + (Pdb) __return__ + 'BAZ' (Pdb) next > (4)test_function() -> test_function3(kwonly=True)