Implement nonlocal variables scoping rule for rename refactor
維護者通常 6 天內回覆
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 48/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- python
研究方向
Start by reading the rename refactor implementation and its tests for variable scope handling; the issue does not name specific files or tests. Trace how definitions and references are resolved across nested functions, then add coverage for the nonlocal cases in the example. Done means renaming the variable defined in outer updates its nested nonlocal references and read, while leaving the global name and inner4 variable unchanged.
由索引模型根據 Issue 內容生成。
描述
Is your feature request related to a problem? Please describe.
Rename refactor does not understand nonlocal variables scoping rules at all.
Describe the solution you'd like
Given this code:
var_x = "global" # shadowed variable in global scope should not be renamed
def outer():
def inner1():
nonlocal var_x # when renaming this
var_x = 1
def inner2():
nonlocal var_x # declared nonlocal from a different inner function, should be renamed
var_x = 2
def inner3():
print(var_x) # undeclared read-only nonlocal, should be renamed
def inner4():
var_x = 4 # this creates separate scope, should not be renamed
var_x = None # this is the definition location of the var_x, should be renamed
# var_x: int # variable can also be declared by type hint without assignment
return var_x
Currently rename refactor only rename variables in one function at a time.
-
Expected code after refactoring: All instances of
var_xinsider outer, except inner4 should be renamed. -
Describe the error or unexpected result that you are getting: currently, each function gets treated as their own scope and inner functions variables don't get renamed and vice versa
Editor information (please complete the following information):
- Rope version: 1.15.2
- 主要語言
- Python
- 星號
- 2.2k
- 分支
- 197
- 平均合併
- 2 天 20 小時
- 30 天內合併 PR
- 9
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python-rope/rope 的其他 Issue
-
難度 1/5 1-3 小時 新手友好度 88/100
python-rope/rope#927 ·
維護者通常 6 天內回覆
-
Extract raises IndexError or ModuleSyntaxError instead of RefactoringError for an empty or whitespace-only region可能已有人在做 @aliassar 於 4 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
python-rope/rope#926 ·
維護者通常 6 天內回覆
-
simplify.real_code blanks t-strings, so renames inside them edit the wrong offset可能已有人在做 @sean0407 於 15 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 83/100
python-rope/rope#913 ·
維護者通常 6 天內回覆
-
難度 4/5 3-5 天 新手友好度 30/100
python-rope/rope#925 ·
維護者通常 6 天內回覆
-
Extract method/variable and introduce parameter don't check whether the new name is already in use可能已有人在做 @aliassar 於 3 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 62/100
python-rope/rope#924 · 2 則留言 ·
維護者通常 6 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
huggingface/accelerate#4511 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
pylint-dev/pylint#11791 ·
維護者通常 1 天內回覆
-
Rasterio granule reads never retry, so one 503 (Service Unavailable) fails the whole request可能已有人在做 @chuckwondo 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
developmentseed/titiler-cmr#305 ·
維護者通常 1 天內回覆
-
community enhancement
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆