Confusing syntax error for missing comma after import-as target
未關閉
還沒有人認領這個 Issue。
3.14
3.15
interpreter-core
topic-parser
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
Right now we have:
>>> import a as a b
File "<python-input-0>", line 1
import a as a b
^
SyntaxError: cannot use name as import target
>>> from x import a as a b
File "<python-input-1>", line 1
from x import a as a b
^
SyntaxError: cannot use name as import target
This happens since these cases match these two rules.
One possible fix would be to add NAME to the list of not-matched tokens so that the current rules don't match this case.
However, I have an idea for a slightly nicer error. PR forthcoming.
cc @pablogsal @lysnikolaou @sobolevn
CPython versions tested on:
3.14, 3.15, CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-146493
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
在 Python REPL 中重現兩個 import-as 範例,然後檢查 Grammar/python.gram 中約在第 1435 行和第 1439 行的兩個相符規則。將產生的診斷與 issue 中描述的預期行為進行比較;缺少逗號的情況收到更清楚的語法錯誤,即表示完成。已註明一個相關的 PR。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- compilers
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100