[Bug]: `compile()` checks the source before `mode`, raising `TypeError` instead of `ValueError`
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
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
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
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus oracle/graalpython
-
[Bug]: sys.flags.debug is 1 whenever optimization is offEvtl. vergeben @hippi345 hat das vor 12 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
oracle/graalpython#1213 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
oracle/graalpython#1105 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
oracle/graalpython#1102 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
oracle/graalpython#1217 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 54/100
oracle/graalpython#1212 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in oracle/graalpython
Ähnliche Issues
-
area/profiles comp/cli P3 type/feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
NousResearch/hermes-agent#146372 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
[oblt-aw][autodoc] Document obs-aw-automerge contract and fix automerge doc inconsistenciesEvtl. vergeben @github-actions hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
GeoSeries scale and skew tests fail with pytest 9.2.0Evtl. vergeben @jiayuasu hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
admission-deferred priority: medium status: ready work-class: scoped
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
melodic-software/claude-code-plugins#10887 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag