A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/issues/103693 below:

Add convenience variables to `pdb` · Issue #103693 · python/cpython · GitHub

Feature or enhancement

Add convenience variables like $foo to pdb, which would be global and temporary. There is a similar feature in gdb.

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 when pdb 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 use retval, 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 the f_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

This could be easily extended in the future to store variables that users are interested in but don't have easy access to.

Linked PRs

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4