Implement nonlocal variables scoping rule for rename refactor
Mantenedores costumam responder em até 2 dias
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 48/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- python
- Domínio
- developer-experience, tooling
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- Python
- Estrelas
- 2.2k
- Forks
- 197
- Merge médio
- 1d 20h
- PRs com merge (30d)
- 7
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de python-rope/rope
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 88/100
python-rope/rope#927 ·
Mantenedores costumam responder em até 2 dias
-
Extract raises IndexError or ModuleSyntaxError instead of RefactoringError for an empty or whitespace-only regionTalvez já em andamento @aliassar assumiu há 3 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
python-rope/rope#926 ·
Mantenedores costumam responder em até 2 dias
-
simplify.real_code blanks t-strings, so renames inside them edit the wrong offsetTalvez já em andamento @sean0407 assumiu há 14 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
python-rope/rope#913 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 30/100
python-rope/rope#925 ·
Mantenedores costumam responder em até 2 dias
-
Extract method/variable and introduce parameter don't check whether the new name is already in useTalvez já em andamento @aliassar assumiu há 2 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 62/100
python-rope/rope#924 · 2 comentários ·
Mantenedores costumam responder em até 2 dias
Todas as issues de python-rope/rope
Issues semelhantes
-
Remove the `pull_request_target` workflow before GitHub blocks itTalvez já em andamento @jat255 assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
IBM/mcp-context-forge#7483 ·
Mantenedores costumam responder em até 2 dias
-
bug good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
[Bug Report]: OpenAI 辅助 API 连通性测试因输出上限仅 1 token 误报“未知错误”Talvez já em andamento @fjfanjian assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Project-N-E-K-O/N.E.K.O#3640 ·
Mantenedores costumam responder em até 1 dia
-
author-page correction
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
acl-org/acl-anthology#10808 · 1 comentário ·
Mantenedores costumam responder em até 1 dia