I encountered this strange behavior in VS Code debugger when stepping line by line through the code.
Before print(var1), when I execute del var1 in the Debug Console, it will delete var1, and the next line print(var1) will fail as expected.
However, in main(), when I execute del var2 in the Debug Console, it doesn't do anything. The next line print(var2) executes successfully. var2 = 'new' will change the value in Debug Console, but del var2 doesn't delete the variable.
Is there any reason for this inconsistent behavior? It seems VS Code Debug Consol won't delete variables inside a function. When I do the same debugging with pdb, it works as expected (var2 gets deleted).
var1 = 'value1'
# del var1 (in vscode Debug Console)
print(var1)
def main():
var2 = 'value2'
# del var2 (in vscode Debug Console)
print(var2)
main()
VS Code v1.61.1 (Sep 2021)
Python v3.9.5