Same arguments and more similar documentation for exec() and for eval().
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
bltinmodule.c と bltinmodule.c.h から始め、特に builtin_exec_impl()、builtin_eval_impl()、builtin_exec()、builtin_eval() を確認してください。引数とクロージャの意図された動作を決める前に、リンクされている Python の議論を読み、その後 exec() と eval() のドキュメントを確認してください。実装とドキュメントが合意された動作を一貫して説明し、サポートしていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend, documentation
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100