Implement nonlocal variables scoping rule for rename refactor

オープン
#935 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@ryanchou1994 がすでに取り組んでいます。

2026年11月6日 から。

  • #936 @ryanchou1994 による — オープン

評価

難易度
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 の本文から書いたものです。

説明

bug

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
    return var_x

Currently rename refactor only rename variables in one function at a time.

  1. Expected code after refactoring: All instances of var_x insider outer, except inner4 should be renamed.

  2. 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
平均マージ
1日 20時間
マージ済み PR(30日)
7

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-rope/rope のほかの issue

python-rope/rope の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。