final TypedDict with total=False does not allow clear/popitem
オープン
まだ誰も着手していません。
bug
topic-final
topic-typed-dict
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
Bug Report
PEP-589 disallows clear and popitem on TypedDicts, even if all known keys are not required, as there may be other required keys due to structural subtyping. However, a @final-decorated TypedDict cannot be structurally subtyped, so these methods should be available.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=7d42af8206cb1e25a53673bdf4e99df1
from typing import TypedDict, final
@final
class A(TypedDict, total=False):
k: int
a: A = {"k": 1}
a.clear()
Expected Behavior
No errors
Actual Behavior
error: "A" has no attribute "clear" [attr-defined]
Your Environment
- Mypy version used: 1.0.0
- Python version used: 3.11
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている mypy-play の再現例を Python 3.11 と mypy 1.0.0 で開始し、その後、type checker が total=False の final TypedDict に対して clear と popitem をどのように処理するかを調べます。完了の条件は、例がエラーを生成せず、構造的に subtypeable な TypedDict に対する既存の制限が維持されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100