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

未關閉
#152,631 0 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

@sobolevn 已經在處理了。

開始於 2026年6月29日。

評估

這個 Issue 還沒有評估資料。

描述

interpreter-core topic-lazy-imports topic-parser type-bug

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
主要語言
Python
星號
77.2k
分支
36k
平均合併
1 天 9 小時
30 天內合併 PR
558

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。