Clarify which variables appear in function.__closure__
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
While working with nested functions, I observed that function.__closure__ only
contains cells for variables that are actually referenced inside the inner
function body. Variables defined in the enclosing scope but not used in the
inner function do not appear in co_freevars and therefore do not appear in
function.__closure__.
Example:
def outer():
x = 1
y = 2
z = 3
def inner():
return x
return inner
inner.__closure__ # contains only x
This behavior matches the execution model (“free variables”), but the current
documentation only states that __closure__ contains bindings for names listed
in co_freevars. It does not explicitly state that only referenced names are
included.
This PR proposes adding a brief clarification to make this behavior explicit.
Before continuing with the pull request, I would like confirmation from the
documentation team whether this detail should be included in the data model
section.
Linked PRs
- gh-142086
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Python データモデルのドキュメントから始め、co_freevars と併せて function.closure の既存の説明を確認します。内側の関数が参照する名前だけが含まれることを明確にし、先に進む前にドキュメントチームと文言を確認します。関連するセクションで動作が明示されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100