microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 769 forks source link

[Bug] F2 Renames Shadowed Variables Globally #4914

Open Servinjesus1 opened 1 year ago

Servinjesus1 commented 1 year ago

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:

Test1

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.

heejaechang commented 1 year ago

looks like a bug. thank you for reporting.