python / python/cpython

Conflict between pragmatic locations and pure spans

Aperta
#94,758 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

3.12 interpreter-core type-bug
Lingua principale
Python
Stelle
77.2k
Fork
36k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

The PEG parser produces locations for an AST that span the entire AST node. This is well defined, and has a number of desirable properties such as the span of a node including all its children's spans.

Unfortunately, this does not produce good locations for tracing and debugging, so we transform some locations in the compiler.
This is problematic as it means that tools producing as AST (e.g. pytest) need to second guess what transformations that the compiler will make.

I proposed moving these transformations in the parser in https://github.com/python/cpython/issues/94694, but as @pablogsal points out, this means that tools which consume the AST (e.g. type checkers) need to undo the transformations to get the original spans back.

The core problem is that there are tools that consume the AST produced by the parser, and tools that produce ASTs for consumption by the compiler, and they want subtly different ASTs.

One possible fix for this is to add a keyword argument to compile() to specify whether it should modify the locations. This would allow pytest, etc. to pass location information through compile() unmodified when needed.

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia leggendo l’issue 94694 e la gestione delle locations dell’AST da parte del parser/compiler. Confronta le esigenze dei consumatori di AST con quelle degli strumenti che producono AST per compile(), quindi determina se un’opzione per preservare le locations sia sufficiente. Il lavoro è completo quando il comportamento delle locations è definito senza richiedere agli strumenti di indovinare o annullare le trasformazioni del compiler.

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

Valutazione

Stack tecnologico
python
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.