You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
romuald commented on Aug 4, 2021
romualdmannequin
MannequinAuthor
More actions
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?
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.
Activity
romuald commentedon Dec 1, 2020
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:
(pdb) retval
<ComplexObject instance at 0x1234>
(pdb) retval zz
(pdb) zz.attribute
'some value'
iritkatriel commentedon Aug 3, 2021
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.
[-]pdb access to return value[/-][+][doc] pdb access to return value[/+][-]pdb access to return value[/-][+][doc] pdb access to return value[/+]iritkatriel commentedon Aug 3, 2021
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.
romuald commentedon Aug 4, 2021
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?
iritkatriel commentedon Aug 4, 2021
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.
gaogaotiantian commentedon Oct 7, 2023
The return value can be accessed with
$_retvalnow.