Doc string for locals() partly contradicts the full documentation
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
locals() documentation
>>> print(locals.__doc__)
Return a dictionary containing the current scope's local variables.
NOTE: Whether or not updates to this dictionary will affect name lookups in
the local scope and vice-versa is *implementation dependent* and not
covered by any backwards compatibility guarantees.
But in the docs:
At module scope, as well as when using exec() or eval() with a single namespace [...]
At class scope [...]
When using exec() or eval() with separate local and global arguments [...]
In all of the above cases, each call to locals() in a given frame of execution will return the same mapping object. Changes made through the mapping object returned from locals() will be visible as assigned, reassigned, or deleted local variables, and assigning, reassigning, or deleting local variables will immediately affect the contents of the returned mapping object.
In an optimized scope (including functions, generators, and coroutines), each call to locals() instead returns a fresh dictionary containing the current bindings of the function’s local variables and any nonlocal cell references. In this case, name binding changes made via the returned dict are not written back to the corresponding local variables or nonlocal cell references, and assigning, reassigning, or deleting local variables and nonlocal cell references does not affect the contents of previously returned dictionaries.
So either:
- Behaviour is undefined and the full documentation fails to mention this in giving a complete description of it
- The behaviour given in the full documentation is stable and can be relied upon, in which case the doc string is misleading
It feels like at least one of the two should be corrected/clarified.
Linked PRs
- gh-127225
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず locals() の docstring の出力と、リンクされている PR gh-127225 を確認し、その後、ドキュメント化された locals() エントリの説明と比較してください。列挙されたスコープのケースを正確にカバーする文言を判断してください。docstring と完全なドキュメントの間に矛盾がなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100