Project.validate() can't detect content changes served by a custom fscommands
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
- 30/100
Direção de pesquisa
Start from the reproduction script in the issue, which shows that Project.validate() keeps the cached module after an fscommands read() override changes the content. Read ChangeIndicator, which compares os.path.getmtime() and os.path.getsize(), and the Project.validate() path that uses it. The issue offers two designs (a forced invalidation for one resource, or an optional change-indicator hook on fscommands), so the maintainers need to choose one before a patch. Done means the cached module reflects the overlay text after validate(), with existing fscommands implementations still working.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
A custom fscommands.read() lets an editor or a language server give Rope the contents of unsaved buffers. pylsp-rope's WorkspaceFileCommands does this, and so will rope-language-server. Rope caches parsed modules, though, and Project.validate() decides whether a file changed only from ChangeIndicator, which calls os.path.getmtime() and os.path.getsize() on the real file. An edit to a buffer changes neither, so Rope keeps analysing the old module even after validate().
To Reproduce
import pathlib
import tempfile
from rope.base import fscommands
from rope.base.project import Project
class Overlay(fscommands.FileSystemCommands):
"""Serve unsaved editor buffers, fall back to the disk."""
def __init__(self):
self.buffers = {}
def read(self, path):
if path in self.buffers:
return self.buffers[path].encode()
return super().read(path)
root = pathlib.Path(tempfile.mkdtemp())
(root / "m.py").write_text("def f():\n return 1\n")
overlay = Overlay()
project = Project(str(root), ropefolder=None, fscommands=overlay)
resource = project.get_resource("m.py")
print(sorted(project.get_pymodule(resource).get_attributes()))
overlay.buffers[resource.real_path] = "def g():\n return 2\n"
project.validate(resource)
print(sorted(project.get_pymodule(resource).get_attributes()))
print(resource.read())
Output on master (46ebf37), Python 3.13:
['f']
['f']
def g():
return 2
resource.read() returns the new text, but the cached module still has f and not g. Refactorings then compute offsets against text the user no longer has.
Workarounds today
- pylsp-rope calls the private
project.pycore._invalidate_resource_cache(resource)for every open document on every request. libutils.report_change()does invalidate, but the documentation describes it as the call to make after saving, and with the defaultautomatic_soa=Trueit also runs static object analysis on every call. That's too slow to run on every keystroke.
Proposal
Either of these would be enough, and neither changes the existing fscommands contract:
- A public way to invalidate one resource, for example
project.invalidate(resource)orproject.validate(resource, force=True). This only needs to notify the resource observers, without the analysis thatreport_change()adds. - An optional hook, for example
fscommands.get_change_indicator(path), whichChangeIndicatoruses when the fscommands object provides it, and falls back toos.stat()otherwise. An overlay could then return the buffer version.
The second option is close to part of #911, but kept optional, which matches the concern raised in the review of #911 that new fscommands methods must not break existing implementations such as pylsp-rope's.
Editor information
- Python 3.13
- Rope master 46ebf37 (also 1.14.0)
- Context: rope-language-server issue #19
- 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 hoje. 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á 11 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
python-rope/rope#913 ·
Mantenedores costumam responder em até 7 dias
-
Extract method/variable and introduce parameter don't check whether the new name is already in useAberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 62/100
python-rope/rope#924 ·
Mantenedores costumam responder em até 7 dias
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
python-rope/rope#923 ·
Mantenedores costumam responder em até 7 dias
Todas as issues de python-rope/rope
Issues semelhantes
-
Backend issue lists report in-patch warnings and out-of-patch errors as not publishableTalvez já em andamento @RaphaelFakhri assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
mozilla/code-review#3794 ·
Mantenedores costumam responder em até 1 dia
-
[oblt-aw][autodoc] Update docs that still describe the security registry as emptyTalvez já em andamento @github-actions assumiu hoje. Aberta
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 85/100
Mantenedores costumam responder em até 1 dia
-
[Bug] adb backup script reports "Done" & exits 0 when the backup failsTalvez já em andamento @bhattmanthan assumiu hoje. Abertarequest-issue-assignment
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
OWASP/mastg#4034 · 5 comentários ·
Mantenedores costumam responder em até 1 dia
-
agent-ui bug p2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
amd/gaia#6580 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
correction metadata
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
acl-org/acl-anthology#10768 · 1 comentário ·
Mantenedores costumam responder em até 1 dia