Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

[Bug]: `compile()` checks the source before `mode`, raising `TypeError` instead of `ValueError`

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

維護者通常 1 天內回覆

已經有一個關聯 PR 被合併了。

  • #1229 來自 @jseop-lim —— 已合併

評估

難度
3/5
預估耗時
1-2 天
新手友好度
76/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
java, python
領域
backend, testing

研究方向

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 內容生成。

描述

bug
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

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

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

oracle/graalpython 的其他 Issue

查看 oracle/graalpython 的全部 Issue

相似的 Issue

更多 Python Issue

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

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