Rename and inline silently skip modules with syntax errors when ignore_syntax_errors is set
Mantenedores costumam responder em até 7 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- python
- Domínio
- developer-experience
Direção de pesquisa
Start with the repro script, which uses Rename from rope.refactor.rename and inline.create_inline from rope.refactor.inline under ignore_syntax_errors=True, and compare with the run that raises ModuleSyntaxError when the flag is off. Trace where the occurrence finder skips unparseable modules and where the ChangeSet is built. Done means a caller can learn which module was skipped, either through a per-call override that raises or through a list of skipped resources, and the maintainers have picked one of those approaches.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
With ignore_syntax_errors=True, cross-module refactorings treat a module that fails to parse as if it contained no occurrences. The module is left out of the ChangeSet and nothing tells the caller, so the refactoring leaves broken code behind.
Editors and language servers have to set this preference, because a project nearly always has a file that is half-edited. So every Rope-based tool can hit this, and the user only finds out when the skipped module fails at import time.
To Reproduce
import pathlib
import tempfile
from rope.base.project import Project
from rope.refactor import inline
from rope.refactor.rename import Rename
root = pathlib.Path(tempfile.mkdtemp())
(root / "a.py").write_text("def helper(x):\n return x * 2\n")
(root / "b.py").write_text("from a import helper\nprint(helper(3))\n")
# c.py uses helper too, but has a syntax error further down
(root / "c.py").write_text("from a import helper\nprint(helper(4))\nif\n")
for name, make in [
("rename", lambda p, r: Rename(p, r, 4).get_changes("double")),
("inline", lambda p, r: inline.create_inline(p, r, 4).get_changes()),
]:
project = Project(str(root), ropefolder=None, ignore_syntax_errors=True)
changes = make(project, project.get_resource("a.py"))
print(name, sorted(c.resource.path for c in changes.changes))
Output on master (46ebf37), Python 3.13:
rename ['a.py', 'b.py']
inline ['a.py', 'b.py']
After the rename, c.py still imports helper, which no longer exists. After the inline, a.py is empty and c.py imports a function that has been deleted. Without ignore_syntax_errors, both refactorings raise ModuleSyntaxError for c.py, which is the safe outcome.
Expected behaviour
The caller should learn that a module which may contain occurrences could not be analysed, so that it can refuse the refactoring or warn the user. Some possible approaches:
- A per-call override, such as
get_changes(..., ignore_syntax_errors=False), that raisesModuleSyntaxErrornaming the module, even when the project preference is set. - A list of the skipped resources, on the ChangeSet or the task handle.
Either would be enough. The occurrence finder already filters modules by a textual match before parsing them, so only modules that mention the name would need to be reported.
Editor information
- Python 3.13
- Rope master 46ebf37 (also 1.14.0)
- Found while adding Rope refactorings to rope-language-server, which has to set
ignore_syntax_errors
- Linguagem predominante
- Python
- Estrelas
- 2.2k
- Forks
- 197
- Merge médio
- 2d 13h
- PRs com merge (30d)
- 5
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é 7 dias
-
Extract raises IndexError or ModuleSyntaxError instead of RefactoringError for an empty or whitespace-only regionTalvez já em andamento @aliassar assumiu há 1 dia. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
python-rope/rope#926 ·
Mantenedores costumam responder em até 7 dias
-
simplify.real_code blanks t-strings, so renames inside them edit the wrong offsetTalvez já em andamento @sean0407 assumiu há 12 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
python-rope/rope#913 ·
Mantenedores costumam responder em até 7 dias
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 30/100
python-rope/rope#925 ·
Mantenedores costumam responder em até 7 dias
-
Extract method/variable and introduce parameter don't check whether the new name is already in useTalvez já em andamento @aliassar assumiu hoje. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 62/100
python-rope/rope#924 · 1 comentário ·
Mantenedores costumam responder em até 7 dias
Todas as issues de python-rope/rope
Issues semelhantes
-
bug severity:low
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 2 dias
-
curriculum documentation quality
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
githubnext/gh-aw-workshop#5367 ·
Mantenedores costumam responder em até 3 dias
-
OAuth documentation for GET /api/v2/users/me/ appears inconsistent with required global read scopeAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 1 dia
-
Create Noise Latents ignores randomize_seed and produces the same noise every runTalvez já em andamento @griptapeops assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
griptape-ai/griptape-nodes-library-diffusers#127 ·
Mantenedores costumam responder em até 1 dia
-
Jenkins capacity report: metrics history is lost when archiving a month failsTalvez já em andamento @RaphaelFakhri assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
adoptium/infrastructure#4568 ·
Mantenedores costumam responder em até 1 dia