Implement nonlocal variables scoping rule for rename refactor

Aperta
#935 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@ryanchou1994 ci sta già lavorando.

Dal 6/11/2026.

  • #936 di @ryanchou1994 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
2.2k
Fork
197
Merge medio
1g 20h
PR unite (30g)
7

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-rope/rope

Tutte le issue di python-rope/rope

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.