Skip to content

ast.parse with lower feature_version is still allowed to parse lazy import os #152631

Open

Description

@sobolevn

Bug report

Code:

>>> import ast
>>> ast.parse('lazy import os', feature_version=(3, 12))

Works and parses lazy import on older python versions :(

It should produce something like:

>>> import ast
>>> ast.parse('lazy import os', feature_version=(3, 12))
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    ast.parse('lazy import os', feature_version=(3, 12))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython/Lib/ast.py", line 46, in parse
    return compile(source, filename, mode, flags,
                   _feature_version=feature_version, optimize=optimize,
                   module=module)
  File "<unknown>", line 1
    lazy import os
                  ^
SyntaxError: Lazy imports are only supported in Python 3.15 and greater

I have a PR ready.

Linked PRs

Activity

  1. self-assigned this
    on Jun 29, 2026
  2. added 2 commits that reference this issue on Jun 29, 2026
  3. changed the title [-]`ast.parse` with lower `feature_version` is still allowed to parser `lazy import os`[/-] [+]`ast.parse` with lower `feature_version` is still allowed to parse `lazy import os`[/+] on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions