Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa
#1,224 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #1229 di @jseop-lim — integrata

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java, python
Ambito
backend, testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
1.7k
Fork
163
Merge medio
14h 10m
PR unite (30g)
56

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di oracle/graalpython

Tutte le issue di oracle/graalpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.