Support for default types in TypedDict
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
This problem arose from trying to type the environ argument for a WSGI application. There are specific keys of the environ dict that have non-str types, and then all the other keys are HTTP_ variables (or server-defined variables, which can be ignored for this purpose) with type str (or Text, depending on the version of Python).
I would like to get stronger typing on environ than Dict[str, Any], but there isn't a way to do that with TypedDict currently because the set of possible keys is unbounded (the client can send any HTTP header).
Ideally, I'd like to be able to do something like:
EnvironDict = TypedDict("EnvironDict", {
"wsgi.version": Tuple[int, int],
"wsgi.input": IO[str],
# ...
}, default_type=str, total=False)
and have this mean that any key is allowed in the dictionary and all unknown keys get a value type of str.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue では、WSGI environ の例を動機として、それ以外は未知のキーに対するデフォルト値型を TypedDict に追加することを説明しています。まず mypy の既存の TypedDict サポートとそのテストを確認してください。提案する構文が定義され、任意のキーがデフォルト型を受け取り、明示的なキーがそれぞれの型を維持し、その動作がテストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100