[Bug]: `compile()` checks the source before `mode`, raising `TypeError` instead of `ValueError`
維護者通常 1 天內回覆
已經有一個關聯 PR 被合併了。
- #1229 來自 @jseop-lim —— 已合併
評估
研究方向
Start in BuiltinFunctions.java at CompileNode.generic, then trace getParserInputType and checkSource in the same file. Reproduce with compile(None, 'f', 'x') and add or update regression tests for invalid mode combined with invalid string, bytes, and AST sources. Done means invalid mode raises ValueError before source conversion errors, matching the reported CPython behavior.
由索引模型根據 Issue 內容生成。
描述
Describe the bug
compile() converts and checks source before it validates mode. When both are invalid, GraalPy reports the source error, while CPython reports the mode with ValueError.
Operating system
Linux
CPU architecture
ARM64
GraalPy version
25.0.2 (Python 3.12.8); also reproduced on 25.2.4
JDK version
No response
Context configuration
No response
Steps to reproduce
compile(None, 'f', 'x')
GraalPy 25.0.2:
TypeError: compile() arg 1 must be a string, bytes or AST object
Expected behavior
CPython 3.12.13:
ValueError: compile() mode must be 'exec', 'eval' or 'single'
Stack trace
Additional context
The same order shows up for string and bytes sources: compile('\x00', 'f', 'x') and compile(b'\xff', 'f', 'x') raise SyntaxError on GraalPy and ValueError on CPython. An AST source already gets the mode checked first.
Root Cause
CompileNode.generic runs checkFlags and checkOptimize, then calls sourceAsString (BuiltinFunctions.java#L1088-L1108), which raises the TypeError (#L1183-L1185). mode is only read later, by getParserInputType inside compile, and that method also runs checkSource first (#L1012-L1018). CPython's builtin_compile_impl dispatches on mode (bltinmodule.c#L776-L798) before it converts the source (#L826).
Fix Suggestion
Call getParserInputType(mode, flags) right after checkOptimize in generic, and move it above checkSource in compile.
- 主要語言
- Python
- 星號
- 1.7k
- 分支
- 163
- 平均合併
- 14 小時 10 分鐘
- 30 天內合併 PR
- 56
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
oracle/graalpython 的其他 Issue
-
[Bug]: sys.flags.debug is 1 whenever optimization is off可能已有人在做 @hippi345 於 12 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
oracle/graalpython#1213 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 74/100
oracle/graalpython#1105 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
oracle/graalpython#1102 ·
維護者通常 1 天內回覆
-
enhancement
難度 4/5 3-5 天 新手友好度 35/100
oracle/graalpython#1217 ·
維護者通常 1 天內回覆
-
enhancement
難度 4/5 3-5 天 新手友好度 54/100
oracle/graalpython#1212 ·
維護者通常 1 天內回覆
查看 oracle/graalpython 的全部 Issue
相似的 Issue
-
area/profiles comp/cli P3 type/feature
難度 2/5 1-3 小時 新手友好度 74/100
NousResearch/hermes-agent#146372 ·
維護者通常 1 天內回覆
-
[BUG] OpenAI-compatible embedding model alias breaks embedder construction可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
[oblt-aw][autodoc] Document obs-aw-automerge contract and fix automerge doc inconsistencies可能已有人在做 @github-actions 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
GeoSeries scale and skew tests fail with pytest 9.2.0可能已有人在做 @jiayuasu 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
admission-deferred priority: medium status: ready work-class: scoped
難度 2/5 1-3 小時 新手友好度 70/100
melodic-software/claude-code-plugins#10887 · 4 則留言 ·
維護者通常 1 天內回覆