Skip to content

ast.ImportFrom.level is incorrectly marked as optional #135959

Open
@JelleZijlstra

Description

@JelleZijlstra

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

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy