Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
Feature or enhancement
Add convenience variables like$foo
topdb
, which would be global and temporary. There is a similar feature ingdb
.
Pitch
Currently, if the user needs to store something temporarily, they need to use a real variable in the current frame, which could potentially interfere with their program (overwrite an existing variable, or messing up with checks in the future). Also, there is no easy way for the users to create a variable that's accessible when they explore every frame.
An easily distinguishable variable (that starts with$
) which is global and temporary would solve this issue. Behind the curtain, we simply replace the variable with a secret variable in global dict and clear the dict whenpdb
gives control back to the program.
With this feature, we actually solves another issue - it's super non-intuitive to access to some key data in the debugger. For example,retval
. There's an issue for this#86690. You can display the value useretval
, but to actually get access to it, you need something undocumented and hacky -locals()['__return__']
. You can only do that when you are in the frame that's returning (which kind of makes sense, but only the BOTTOM ONE frame can be at this state). Also, there's thef_locals
disaster that we have not yet solved#102864.
Another example would be the current frame. You'd be surprised that it's super difficult to access the current frame object you are debugging,sys._getframe()
and its variance won't give you what you want.
So, we introduce a couple of internal convenience variables
$_frame
- the current frame being debugged$_retval
- the return value if the bottom function is returning (this is globally distinct)$_exception
- the (exc_type, exc_value) tuple if an exception is being raised
This could be easily extended in the future to store variables that users are interested in but don't have easy access to.