-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add convenience variables to pdb
#103693
Comments
Exec_value currently means the exception itself, making exec_type == exec_value.class redundant. I would just make $_exception the exception. @iritkatriel do you agree? |
I actually think making If we can gradually deprecate the secret local variable, it might clean up the structure even more. aka replace However, the behavior of But for now, I do believe convenience variable is a helpful improvement. |
Yes, the type is redundant. |
@iritkatriel actually, |
If you’re going to deprecate the local then I think there’s no point changing it. |
Okay I made some changes:
|
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 raisedThis could be easily extended in the future to store variables that users are interested in but don't have easy access to.
Linked PRs
pdb
#103694The text was updated successfully, but these errors were encountered: