Specialize empty collections to Any as a fallback
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Context
I have a pending PR for typeshed which fixes overparameterized dict.get and dict.pop methods: python/typeshed#10294. The PR causes a lot of failures in various GitHub projects due to how mypy treats empty collections. Specifically, if dict.get is annotated as
class dict(Generic[KT, VT]):
def get(self, key: KT, default: T) -> T | VT: ...
mypy infers the type of v in
def test(d: dict[str, Any]):
v = d.get("foo", {})
to be Any | dict[<unknown>, <unknown>], instead of Any | dict[Any, Any].
Feature
Specialize empty collections to Any if no other information is available to recover type arguments.
Pitch
Using <unknown> instead of Any requires users to cast or add type annotations where they otherwise will not be necessary. See comments in the PR for a few examples from real projects.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、示されている dict.get の例を mypy で再現し、型引数を復元できない場合に空のコレクション式がどのように推論されるかを調べます。この状況で空のコレクションが unknown ではなく Any に特殊化され、その動作が関連する型チェックテストで引き続きカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100