Project.validate() can't detect content changes served by a custom fscommands
Maintainer antworten meist innerhalb von 7 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 30/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 2.2k
- Forks
- 197
- Ø Merge
- 2 T. 13 Std.
- Gemergte PRs (30 T.)
- 5
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python-rope/rope
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
python-rope/rope#927 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
Extract raises IndexError or ModuleSyntaxError instead of RefactoringError for an empty or whitespace-only regionEvtl. vergeben @aliassar hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
python-rope/rope#926 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
simplify.real_code blanks t-strings, so renames inside them edit the wrong offsetEvtl. vergeben @sean0407 hat das vor 10 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
python-rope/rope#913 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
Extract method/variable and introduce parameter don't check whether the new name is already in useOffen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 62/100
python-rope/rope#924 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
python-rope/rope#923 ·
Maintainer antworten meist innerhalb von 7 Tagen
Alle Issues in python-rope/rope
Ähnliche Issues
-
New InternshipOffennew_internship
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
get_graph warns that the oneway column is missing when no way has a oneway tagEvtl. vergeben @HTenkanen hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
cython/cython#8110 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
fix: security 🔐 style: article/section 📝 system: data-mgmt 🗃️ system: security 🔐 system: software 💻
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
uabrc/uabrc.github.io#1267 ·
-
Link Checker ReportOffenBot Type: Bug Type: Documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag