python / python/cpython

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

Open
#152,631 0 comments 0 reactions 1 assignee View on GitHub

@sobolevn is already working on this.

Since Jun 29, 2026.

interpreter-core topic-lazy-imports topic-parser type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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
  • gh-152632

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.