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() without optimize=True doesn't error on invalid AST type #130139

Closed
iritkatriel opened this issue Feb 15, 2025 · 1 comment
Closed
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@iritkatriel
Copy link
Member

iritkatriel commented Feb 15, 2025

>>> ast.parse(ast.Constant(42))
Constant(value=42, kind=None)


>>> ast.parse(ast.Constant(42), optimize=True)
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    ast.parse(ast.Constant(42), optimize=True)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/ast.py", line 53, in parse
    return compile(source, filename, mode, flags,
                   _feature_version=feature_version, optimize=optimize)
TypeError: expected Module node, got Constant

(This came up while implementing PEP 765 #130080).

Linked PRs

iritkatriel added a commit to iritkatriel/cpython that referenced this issue Feb 15, 2025
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Feb 15, 2025
@picnixz picnixz added type-feature A feature request or enhancement interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Feb 15, 2025
@tomasr8
Copy link
Member

tomasr8 commented Feb 17, 2025

PR merged, can we close the issue or is there something left to do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants