Skip to content

ast.parse() abuses assert for error checking #95066

Closed
@jwilk

Description

@jwilk

Bug report

ast.parse() uses the assert statement to validate the feature_version argument:

$ python3 -c 'import ast; ast.parse("print", feature_version=(2, 7))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/jwilk/.local/lib/python3.11/ast.py", line 45, in parse
    assert major == 3
AssertionError

This is bad because the check will go away if you enable optimizations:

$ python3 -O -c 'import ast; ast.parse("print", feature_version=(2, 7))' && echo yay
yay

Your environment

Python 3.11.0b4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions