Rename and inline silently skip modules with syntax errors when ignore_syntax_errors is set
Los mantenedores suelen responder en 7 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- developer-experience
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 2.2k
- Forks
- 197
- Merge medio
- 2 d 13 h
- PR fusionados (30 d)
- 5
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python-rope/rope
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
python-rope/rope#927 ·
Los mantenedores suelen responder en 7 días
-
Extract raises IndexError or ModuleSyntaxError instead of RefactoringError for an empty or whitespace-only regionPosiblemente ocupada @aliassar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
python-rope/rope#926 ·
Los mantenedores suelen responder en 7 días
-
simplify.real_code blanks t-strings, so renames inside them edit the wrong offsetPosiblemente ocupada @sean0407 la tomó hace 10 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
python-rope/rope#913 ·
Los mantenedores suelen responder en 7 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
python-rope/rope#925 ·
Los mantenedores suelen responder en 7 días
-
Extract method/variable and introduce parameter don't check whether the new name is already in useAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 62/100
python-rope/rope#924 ·
Los mantenedores suelen responder en 7 días
Todos los issues de python-rope/rope
Issues similares
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
QuantConnect/Documentation#2838 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
awslabs/route53-dynamic-dns-with-lambda#67 · 1 comentario ·
-
`SubAgents` returns a child run's `DeferredToolRequests` to the parent as a successful tool resultAbiertobug pkg:harness
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
pydantic/pydantic-ai#12405 ·
Los mantenedores suelen responder en 1 día
-
good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
good first issue help wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100