Same arguments and more similar documentation for exec() and for eval().
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 558
Descripción
Feature or enhancement
This involves changes to the documentation and to the implementation.
I notice that the arguments for exec() and eval() differ in certain ways, which I believe are unnecessary.
When the source is a code object, both calls result in a call to PyEval_EvalCode or, if closure is given, to PyEval_EvalCodeEx.
When the source is a string, there is no closure argument allowed, and the source is compiled as a file input or as an eval input, and then there is a call to PyRun_String or PyRun_StringFlags.
Therefore, the differences between the two functions are solely in the builtin_exec_impl() and builtin_eval_impl() functions in bltinmodule.c., and builtin_exec() and builtin_eval() in bltinmodule.c.h.
- eval() doesn't take a closure argument. It would be useful if calling eval('x := 3'), for example, if x is a nonlocal variable.
- eval() and exec() both require that a globals argument be an actual dict object or subclass. However, the documentation for exec() is incorrect and should be changed, by removing the phrase ' (and not a subclass of dictionary)'.
- When the first argument is a string, eval() returns the result of compiling and running the string as an expresion, and exec() compiles and runs the string as a file input and returns None.
Pitch
I've had difficulty understanding how both of these functions work, due to confusing documentation of them. They largely say the same thing but in different ways, and this obscures the fact that the two functions are mostly the same.
I imagine that the closure argument was not added to eval() as an oversight. However, eval() could be used to access a nonlocal variable in the caller's namespace in the same way as exec() could. It could even modify the variable if the code object is compiled from an expression containing a walrus.
Previous discussion
discussion.
This discussion post has more details and suggestions for making the proposed changes.
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.
Línea de trabajo
Comienza con bltinmodule.c y bltinmodule.c.h, especialmente con builtin_exec_impl(), builtin_eval_impl(), builtin_exec() y builtin_eval(). Lee la discusión de Python enlazada antes de decidir el comportamiento previsto de los argumentos y los cierres, y después revisa la documentación de exec() y eval(). Se considera terminado cuando la implementación y la documentación describen y admiten de forma coherente el comportamiento acordado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend, documentation
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100