This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [doc] pdb access to return value
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Romuald, iritkatriel
Priority: normal Keywords: patch

Created on 2020-12-01 15:13 by Romuald, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 23601 open Romuald, 2020-12-01 15:25
PR 27612 open Romuald, 2021-08-05 08:10
Messages (5)
msg382259 - (view) Author: Romuald Brunet (Romuald) * Date: 2020-12-01 15:13
When using the pdb module, there is currently no way to easy access the current return value of the stack

This return value is accessed by the 'retval command'

I propose using the currently unused argument to allow storing the return value in the local variables, accessible via the debugger

For example:


    def foo():
        debugger()
        return ComplexObject()

    def bar():
        return foo()

(pdb) retval
<ComplexObject instance at 0x1234>
(pdb) retval zz
(pdb) zz.attribute
'some value'
msg398853 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-08-03 22:40
It actually is in the locals, and it's called __return__. So you can access it with 

locals()['__return__']

I'll try to see where that can be documented.
msg398855 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-08-03 22:57
I just noticed your PR. Would you like to continue working on this?

I think we should update the documentation of retval (in the doc and in the function's doctring) to say:

"""
retval
Print the return value for the last return of a function.  Alternatively, the return value can be accessed with ``locals()['__return__']``.
"""

Then add unit tests and examples as you did.
msg398894 - (view) Author: Romuald Brunet (Romuald) * Date: 2021-08-04 13:12
I'm not sure I follow.

You wish to "simply" update the doc? (and not update the retval to allow storing it into a varible. I'm OK with that)


But if we choose this, I'm not sure what needs changing in the doctests :-?


Another interrogation: is the use locals() really necessary? I can see that I can simply use `__return__` to access the return object.
Is there a reason to access it via locals() inside pdb?
msg398896 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-08-04 13:21
Yes, exactly - to update the doc so that the next person who needs it will easily find a way to do it (which was not available to you when you created this issue).

The test should assert that what the doc says, so that if someone breaks documented functionality we will immediately know.

Your point about accessing __return__ directly from the prompt is interesting - sure, if that works just document that and make sure the test fails if we make a change that breaks it.
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86690
2021-08-05 08:10:47Romualdsetpull_requests: + pull_request26106
2021-08-04 13:21:56iritkatrielsetmessages: + msg398896
2021-08-04 13:12:05Romualdsetmessages: + msg398894
2021-08-03 22:57:46iritkatrielsetmessages: - msg398854
2021-08-03 22:57:37iritkatrielsetmessages: + msg398855
2021-08-03 22:56:46iritkatrielsettitle: pdb access to return value -> [doc] pdb access to return value
messages: + msg398854
versions: + Python 3.9, Python 3.11
2021-08-03 22:40:08iritkatrielsetnosy: + iritkatriel
messages: + msg398853
2020-12-01 15:25:02Romualdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request22470
2020-12-01 15:13:18Romualdcreate