python / python/cpython

ast.ImportFrom.level is incorrectly marked as optional

Offen
#135,959 2 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@JelleZijlstra arbeitet bereits daran.

Seit 26.6.2025.

interpreter-core topic-parser type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug report

Bug description:

The level field on ast.ImportFrom is marked optional in the ASDL definition, but in fact the parser always sets it:

>>> ast.dump(ast.parse('from x import a'))
"Module(body=[ImportFrom(module='x', names=[alias(name='a')], level=0)])"
>>> ast.dump(ast.parse('from .x import a'))
"Module(body=[ImportFrom(module='x', names=[alias(name='a')], level=1)])"
>>> ast.dump(ast.parse('from ...............x import a'))
"Module(body=[ImportFrom(module='x', names=[alias(name='a')], level=15)])"

We should mark the field as required for consistency with the parser.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-135960

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.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

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