The types of `builtins.locals` and `types.FrameType.f_locals` aren't correct
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 2.1k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 82
説明
builtins.locals and types.FrameType.f_locals are currently typed with dict[str, Any], which is incorrect:
-
Counterexample:
from collections import UserDict class A(type): @classmethod def __prepare__(cls, name, bases): return UserDict() def __new__(mcs, name, bases, namespace, /, **kw): return super().__new__(mcs, name, bases, dict(namespace), **kw) class B(metaclass=A): assert isinstance(locals(), dict) # AssertionError -
Counterexample as a consequence of PEP 667 (Python >= 3.13):
from inspect import currentframe def f(): print(type(currentframe().f_locals)) # <class 'FrameLocalsProxy'> (runtime type is `_collections_abc.framelocalsproxy`; not in `.pyi` stubs yet) assert isinstance(currentframe().f_locals, dict) # AssertionError f()
However, I'm not sure what the actual type should be. From what I can gather, the type should implement a mapping interface, with a few (but not all?) MutableMapping methods (PEP 667 describes what these mutable mapping methods are for FrameType.f_locals, but I'm not sure what's exactly expected of builtins.locals()).
In addition, collections.abc.Mapping and collections.abc.MutableMapping themselves are unsuitable, because they're nominal types, although this could be fixed by defining a Protocol which looks like a Mapping.
So, what should the types of builtins.locals and types.FrameType.f_locals be?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
stdlib/builtins.pyi と stdlib/types.pyi にある参照されている宣言から始め、次に PEP 667 の FrameType.f_locals の説明を読み、issue のランタイム例と比較します。locals() と f_locals の両方について互換性のある型を決定して文書化し、構造的マッピングプロトコルが必要かどうかも判断できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100