FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-86690: Add `retval [variable]` option to pdb by romuald · Pull Request #23601 · python/cpython · GitHub

/ cpython Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 11 additions & 3 deletions Lib/pdb.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1149,11 +1149,19 @@ def do_args(self, arg):
do_a = do_args

def do_retval(self, arg):
"""retval
Print the return value for the last return of a function.
"""retval [variable]
Print or store the return value for the last return of a function.

When used without argument, prints the return value

When used with an argument, store the return value into a local variable

"""
if '__return__' in self.curframe_locals:
self.message(repr(self.curframe_locals['__return__']))
if arg:
self.curframe_locals[arg] = self.curframe_locals['__return__']
else:
self.message(repr(self.curframe_locals['__return__']))
else:
self.error('Not yet returned!')
do_rv = do_retval
Expand Down
7 changes: 6 additions & 1 deletion Lib/test/test_pdb.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def test_pdb_basic_commands():
... 'jump 8', # jump over second for loop
... 'return', # return out of function
... 'retval', # display return value
... 'retval v1', # stores the return value in "v1" local variable
... 'v1', # display the "v1" stored variable
... 'next', # step to test_function3()
... 'step', # stepping into test_function3()
... 'args', # display function args
Expand Down Expand Up @@ -139,7 +141,7 @@ def test_pdb_basic_commands():
[EOF]
(Pdb) bt
...
<doctest test.test_pdb.test_pdb_basic_commands[4]>(25)<module>()
<doctest test.test_pdb.test_pdb_basic_commands[4]>(27)<module>()
-> test_function()
<doctest test.test_pdb.test_pdb_basic_commands[3]>(3)test_function()
-> ret = test_function_2('baz')
Expand Down Expand Up @@ -184,6 +186,9 @@ def test_pdb_basic_commands():
-> return foo.upper()
(Pdb) retval
'BAZ'
(Pdb) retval v1
(Pdb) v1
'BAZ'
(Pdb) next
> <doctest test.test_pdb.test_pdb_basic_commands[3]>(4)test_function()
-> test_function3(kwonly=True)
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `retval [variable]` option to pdb

Back | FazBrowse Home | New Git URL