I don't think this is a duplicate, as most others reference F2 not working at all. This feature is working now, but not ideally.
Environment data
VS Code version: 1.81.1
Jupyter Extension version (available under the Extensions sidebar): v2023.7.1002162226
Python Extension version (available under the Extensions sidebar): v2023.14.0
OS (Windows | Mac | Linux distro) and version: Mac Ventura
Python and/or Anaconda version: 3.11.4
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda 22.11.1
Jupyter server running: Local in SSH session
Expected behaviour
F2 should respect scope and not touch global variables when renaming local ones. Rather, F2 will change all instances of global variables if local ones shadow them, but only in other cells.
Actual behaviour
It appears the problem is cell-to-cell loss of scope awareness. So, if you try to rename a variable in one cell that might shadow a global in another (regardless of if those cells have been run or in other words if that global variable is yet in globals), it will rename the global versions as well. If the global's in the same cell, it will rightly ignore those.
Steps to reproduce:
Sometimes undo works, but when recording this I got an unsettling error about "Unable to undo rename variable in all files". I don't think it really means "all files", at least I hope not.
Adaptation
It seems like global variables in Notebooks are as nebulous. I suppose I should make everything in cells be scoped? As we see in the gif, variables are safe when in functions.
I don't think this is a duplicate, as most others reference
F2
not working at all. This feature is working now, but not ideally.Environment data
Expected behaviour
F2
should respect scope and not touch global variables when renaming local ones. Rather,F2
will change all instances of global variables if local ones shadow them, but only in other cells.Actual behaviour
It appears the problem is cell-to-cell loss of scope awareness. So, if you try to rename a variable in one cell that might shadow a global in another (regardless of if those cells have been run or in other words if that global variable is yet in globals), it will rename the global versions as well. If the global's in the same cell, it will rightly ignore those.
Steps to reproduce:
Sometimes undo works, but when recording this I got an unsettling error about "Unable to undo rename variable in all files". I don't think it really means "all files", at least I hope not.
Adaptation
It seems like global variables in Notebooks are as nebulous. I suppose I should make everything in cells be scoped? As we see in the
gif
, variables are safe when in functions.