Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Geschlossen
#1,224 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Ein zugehöriger Pull Request wurde bereits gemerged.

  • #1229 von @jseop-lim — gemerged

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
76/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
java, python
Bereich
backend, testing

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
1.7k
Forks
163
Ø Merge
14 Std. 10 Min.
Gemergte PRs (30 T.)
56

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus oracle/graalpython

Alle Issues in oracle/graalpython

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.