Skip to content

ast.parse() without optimize=True doesn't error on invalid AST type #130139

Closed

Description

@iritkatriel
>>> 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

Activity

  1. added 2 commits that reference this issue on Feb 15, 2025
  2. added a commit that references this issue on Feb 16, 2025
  3. tomasr8 commented on Feb 17, 2025

    @tomasr8
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions