patchedast: visitors that omit sub-nodes leave unconsumed text that later token searches mis-match

Aperta
#912 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 7 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
46/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
devtools

Direzione di ricerca

Start in rope/base/ast.py and trace _PatchingASTWalker plus the visitors named in the issue, including _arguments, _arg, _handle_function_def_node, _JoinedStr, _ClassDef and _TryFinally. Reproduce the listed cases with patchedast.get_patched_ast(src, sorted_children=True), then add a regression check that relevant AST nodes and string literals receive regions covering their AST spans. Done means the cases no longer raise or leave source text without a region.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

_PatchingASTWalker finds each token with a forward source.index, so any source text a visitor does not
list is skipped as whitespace; a (, ), = or quote inside it is then matched as a later token. The
walk raises MismatchedTokenError / AttributeError: 'NoneType' object has no attribute 'group', or it
silently produces wrong regions, which Scope.get_region uses for scope lookup. On rope 1.15.0, each
repro below makes patchedast.get_patched_ast(src, sorted_children=True) either raise or finish with part
of the source left without a region:

  1. posonly / kw-only args and kw_defaults (_arguments): def f(*, m: str = "(host)"): pass
  2. parameter annotations (_arg): def f(p: A[F(d="t")] = None): pass
  3. return annotations (_handle_function_def_node): def f() -> A[F(d="(")]: pass
  4. *args / **kwargs annotations: def f(*a: F("("), **k: F(")")): pass
  5. f-string implicitly concatenated with a later literal (_JoinedStr stops at the f-string's quote):
    c = g(f"{d}" "(")
  6. class keywords (_ClassDef): class A(B, metaclass=M, x=")"): pass
  7. else of try/except/else/finally (_TryFinally): an else: body holding x = "("
  8. rb/Rb prefixes (string pattern [uUbB]?[rR]?): x = rb"("; the region starts after r
  9. 3.14 t-strings: TemplateStr/Interpolation are unknown nodes: f(t"{a}(", ")")
  10. 3.12+ nested f-strings that reuse the outer quote: x = f"{f"{a}("}" ")" (the string regex stops at
    the inner quote)

Suggested regression test: after walking any module, every AST node except context/operator nodes,
withitem and f-string internals has a region, and every string literal's region covers its
ast span. With that check, CPython's stdlib and a 1,200-file project pass once the visitors above are
fixed. We carry these patches in living-architecture's rope_patches.py and will drop each when it
lands upstream.

Lingua principale
Python
Stelle
2.2k
Fork
197
Merge medio
2g 13h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-rope/rope

Tutte le issue di python-rope/rope

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.