Skip to content

Account for the scope when changing variables #1869

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

Merged
merged 5 commits into from
Mar 10, 2025

Conversation

rchiodo
Copy link
Contributor

@rchiodo rchiodo commented Mar 10, 2025

In this issue:
#1857

The user is trying to assign the global 'c' to a new value while inside of a function. Since the variable is listed under 'globals', you'd think this would just work.

Internally we don't actually assign it to globals unless the user types globals()['c']=value, but that doesn't really make sense from the variables panel.

I found that the scope of the variable is passed in the setVariables request, so we can use that to determine if the variable was originally a global or not and assign it to the correct scope.

I tested this with Pydevd's test automation and by using VS code.

Addresses #1857

@rchiodo rchiodo requested a review from a team as a code owner March 10, 2025 17:59
@@ -934,7 +934,7 @@ def internal_change_variable_json(py_db, request):
)
return

child_var = variable.change_variable(arguments.name, arguments.value, py_db, fmt=fmt)
child_var = variable.change_variable(arguments.name, arguments.value, py_db, fmt=fmt, scope=scope)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the setVariable request is handled. I added the scope to the change_variable

@rchiodo rchiodo merged commit f7d8963 into microsoft:main Mar 10, 2025
22 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants