Skip to content
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

Set a variable from a different frame #1142

Closed
brichet opened this issue Dec 5, 2022 · 3 comments
Closed

Set a variable from a different frame #1142

brichet opened this issue Dec 5, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@brichet
Copy link

brichet commented Dec 5, 2022

Is there a way to copy a local variable (in a function) to the global scope (module), in order to inspect it after debugging ?

In my experience, sending a setExpression request with a global variable as expression does not create a global variable:

type: "request",
command: "setExpression",
arguments: {
   expression: "globals()['global_variable']", 
   value: "local_variable", 
   frameId: local_function_frame_id
},
seq: XXX,

The above request will create a variable within the frame of the function only. This variable will not be accessible from the frame of the module.

I may have misunderstood how frames and scopes work, I'd be happy to have some clarification if this is the case.

@int19h int19h added enhancement New feature or request and removed needs investigation labels Dec 5, 2022
@int19h
Copy link
Contributor

int19h commented Dec 5, 2022

Also applies when you do "evaluate" with an equivalent assignment. This is kinda related to #1138 - I believe it's the same code that's responsible for the update. But it also seems to not be updating the real globals dict on purpose, so this restriction might be in place to work around some other limitation; @fabioz, does this sound familiar?

@fabioz
Copy link
Collaborator

fabioz commented Dec 8, 2022

The problem is that globals() refers to the globals given at evaluation time which was a dict and not the actual globals from the frame. I've just provided a PR for this.

fabioz added a commit to fabioz/debugpy that referenced this issue Dec 8, 2022
@brichet
Copy link
Author

brichet commented Dec 8, 2022

Thanks @fabioz, after a first quick test, it seems to work well.

@fabioz fabioz closed this as completed in 1c79248 Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants