microsoft / pylance-release

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

Should not rename outer variables while renaming local variables if they're same #6493

Open GF-Huang opened 1 month ago

GF-Huang commented 1 month ago

Type: Bug

Behaviour

https://github.com/user-attachments/assets/cb83edb3-aa20-46c1-b574-06d7459b15aa

Steps to reproduce:

As Behaviour section.

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` XXX ```

Behaviour

XXX

Steps to reproduce:

  1. XXX

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` XXX ```

Extension version: 2024.14.1 VS Code version: Code 1.93.1 (38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, 2024-09-11T17:20:05.685Z) OS version: Windows_NT x64 10.0.22631 Modes:

User Settings

``` condaPath: "" languageServer: "Pylance" ```

Installed Extensions |Extension Name|Extension Id|Version| |---|---|---| |.NET Install Tool|ms-dotnettools.vscode-dotnet-runtime|2.1.6| |十六进制编辑器|ms-vscode.hexeditor|1.10.0| |远程资源管理器|ms-vscode.remote-explorer|0.4.3| |Auto Close Tag|formulahendry.auto-close-tag|0.5.15| |Black Formatter|ms-python.black-formatter|2024.2.0| |C/C++|ms-vscode.cpptools|1.21.6| |C#|ms-dotnettools.csharp|2.45.25| |C# 开发工具包|ms-dotnettools.csdevkit|1.10.18| |Caddyfile Syntax|zamerick.vscode-caddyfile-syntax|1.0.4| |Chinese (Simplified) (简体中文) Language Pack for Visual Studio Code|MS-CEINTL.vscode-language-pack-zh-hans|1.93.2024091109| |Data Wrangler|ms-toolsai.datawrangler|1.10.0| |Docker|ms-azuretools.vscode-docker|1.29.3| |Encode Decode|mitchdenny.ecdc|1.8.0| |Ini for VSCode|DavidWang.ini-for-vscode|0.0.4| |Inno Setup|chouzz.vscode-innosetup|1.9.3| |IntelliSense for CSS class names in HTML|Zignd.html-css-class-completion|1.20.0| |JavaScript (ES6) code snippets|xabikos.JavaScriptSnippets|1.8.0| |JavaScript Debugger|ms-vscode.js-debug|1.93.0| |JavaScript Debugger Companion Extension|ms-vscode.js-debug-companion|1.1.3| |Jupyter|ms-toolsai.jupyter|2024.8.1| |Jupyter Cell Tags|ms-toolsai.vscode-jupyter-cell-tags|0.1.9| |Jupyter Keymap|ms-toolsai.jupyter-keymap|1.1.2| |Jupyter Notebook Renderers|ms-toolsai.jupyter-renderers|1.0.19| |Jupyter Slide Show|ms-toolsai.vscode-jupyter-slideshow|0.1.6| |LeetCode|LeetCode.vscode-leetcode|0.18.4| |Log File Highlighter|emilast.LogFileHighlighter|3.3.3| |Markdown All in One|yzhang.markdown-all-in-one|3.6.2| |Markdown Preview Github Styling|bierner.markdown-preview-github-styles|2.1.0| |Node.js Exec|miramac.vscode-exec-node|0.5.6| |NuGet Gallery|patcx.vscode-nuget-gallery|1.2.1| |Pascal|alefragnani.pascal|9.8.0| |Paste JSON as Code|quicktype.quicktype|23.0.170| |Path Intellisense|christian-kohler.path-intellisense|2.9.0| |Polyglot Notebooks|ms-dotnettools.dotnet-interactive-vscode|1.0.5229040| |PowerShell|ms-vscode.powershell|2024.2.2| |Pylance|ms-python.vscode-pylance|2024.9.2| |Python|ms-python.python|2024.14.1| |Python Debugger|ms-python.debugpy|2024.10.0| |Python Indent|KevinRose.vsc-python-indent|1.18.0| |Rainbow CSV|mechatroner.rainbow-csv|3.12.0| |Red Hat Commons|redhat.vscode-commons|0.0.6| |REG|ionutvmi.reg|1.1.0| |Remote - SSH|ms-vscode-remote.remote-ssh|0.114.3| |Remote - SSH: Editing Configuration Files|ms-vscode-remote.remote-ssh-edit|0.86.0| |Rust Flash Snippets|lorenzopirro.rust-flash-snippets|3.1.0| |rust-analyzer|rust-lang.rust-analyzer|0.3.2121| |SQLite Viewer|qwtel.sqlite-viewer|0.7.2| |systemd-unit-file|coolbear.systemd-unit-file|1.0.6| |Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.9| |Transformer|dakara.transformer|1.12.1| |Valve KeyValue Files Support|GEEKiDoS.vdf|0.0.7| |Visual Studio Keymap|ms-vscode.vs-keybindings|0.2.1| |vscode-proto3|zxh404.vscode-proto3|0.5.5| |WSL|ms-vscode-remote.remote-wsl|0.88.4| |XML Tools|DotJoshJohnson.xml|2.5.1| |YAML|redhat.vscode-yaml|1.15.0|
System Info |Item|Value| |---|---| |CPUs|12th Gen Intel(R) Core(TM) i5-12600KF (16 x 3686)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off| |Load (avg)|undefined| |Memory (System)|31.85GB (14.77GB free)| |Process Argv|--crash-reporter-id b85d9d50-7836-4e27-9948-99978c217f47| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492:30256859 vscod805cf:30301675 binariesv615:30325510 vsaa593:30376534 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 vscrpc:30673769 a9j8j154:30646983 962ge761:30959799 pythongtdpath:30769146 pythonnoceb:30805159 asynctok:30898717 pythonmypyd1:30879173 h48ei257:31000450 pythontbext0:30879054 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 dsvsc021:30996838 da93g388:31013173 a69g1124:31058053 dvdeprecation:31068756 dwnewjupyter:31046869 newcmakeconfigv2:31071590 impr_priority:31102340 nativerepl2:31139839 refactort:31108082 pythonrstrctxt:31112756 flightc:31134773 wkspc-onlycs-t:31132770 wkspc-ranged-c:31125598 cf971741:31144450 defaultse:31146405 iacca2:31144504 cc771715:31146322 ```
rchiodo commented 1 month ago

This only seem to apply to globals specified in cells.

In a python file it only renames the local variable. If the global is defined in the cell first, the rename only applies to the local variable. It must have something to do with builtins, as that's how cells are concatenated together.

KacieKK commented 1 month ago

I can reproduce OP's issue. also, I tried to define a variable within the cell, the rename doesn't apply. But it still applies to other cells. Animation (25)