python / python/cpython

Conflict between pragmatic locations and pure spans

Offen
#94,758 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

3.12 interpreter-core type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Lies zunächst issue 94694 und die Behandlung von AST-Locations durch Parser/Compiler. Vergleiche die Anforderungen von AST-Konsumenten mit denen von Tools, die ASTs für compile() erzeugen, und bestimme dann, ob eine Option zum Beibehalten von Locations ausreicht. Als abgeschlossen gilt die Arbeit, wenn das Verhalten der Locations definiert ist, ohne dass Tools Compiler-Transformationen erraten oder rückgängig machen müssen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.