Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add convenience variables topdb #103693

Closed
Closed
Labels
type-featureA feature request or enhancement
@gaogaotiantian

Description

@gaogaotiantian

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.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp