[Bug]: `compile()` checks the source before `mode`, raising `TypeError` instead of `ValueError`
Los mantenedores suelen responder en 1 día
Ya se ha fusionado un pull request relacionado.
- #1229 de @jseop-lim — fusionado
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 76/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 1.7k
- Forks
- 163
- Merge medio
- 14 h 10 min
- PR fusionados (30 d)
- 56
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de oracle/graalpython
-
[Bug]: sys.flags.debug is 1 whenever optimization is offPosiblemente ocupada @hippi345 la tomó hace 12 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
oracle/graalpython#1213 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
oracle/graalpython#1105 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
oracle/graalpython#1102 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
oracle/graalpython#1217 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 54/100
oracle/graalpython#1212 ·
Los mantenedores suelen responder en 1 día
Todos los issues de oracle/graalpython
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
[oblt-aw][autodoc] Document obs-aw-automerge contract and fix automerge doc inconsistenciesPosiblemente ocupada @github-actions la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
admission-deferred priority: medium status: ready work-class: scoped
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
melodic-software/claude-code-plugins#10887 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
backend bug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
PoCInnovation/Distribox#255 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
google/langextract#598 ·
Los mantenedores suelen responder en 1 día