Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jwilk opened this issue Jul 20, 2022 · 1 comment
Closed

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

jwilk opened this issue Jul 20, 2022 · 1 comment

Comments

@jwilk
Copy link

jwilk commented Jul 20, 2022

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

hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue Jul 20, 2022
ambv pushed a commit that referenced this issue Jul 26, 2022
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
@ambv
Copy link
Contributor

ambv commented Jul 26, 2022

Fixed with #95072. Thanks for the report, @jwilk! ✨ 🍰 ✨

@ambv ambv closed this as completed Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants