Discrepancy between spec and tests on indexing TypedDicts with unknown literal keys
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 302
- 平均マージ
- 23時間
- マージ済み PR(30日)
- 8
説明
Splitting issue from PR https://github.com/python/typing/pull/1978
Spec says that indexing with unknown literal keys should be reported as an error:
The use of a key that is not known to exist should be reported as an error, even if this wouldn’t necessarily generate a runtime type error. These are often mistakes, and these may insert values with an invalid type if structural assignability hides the types of certain items. For example, d[‘x’] = 1 should generate a type check error if ‘x’ is not a valid key for d (which is assumed to be a TypedDict type).
But it's not reflected in conformance tests (https://github.com/python/typing/blob/2d88da2a407b556f5b52b4c6ad1bd659873bb9ac/conformance/tests/typeddicts_operations.py) and there's a bit of discrepancy between type checkers how they handle some cases (most of them reject all cases that may cause runtime error / allow cases that do not cause runtime error ).
Would be great if we can either adapt conformance tests to the spec or amend the spec to remove the ambiguity.
Related discussion - https://discuss.python.org/t/typeddict-operations-with-unknown-literal-keys/89653 (also has information on state of this issue in different type checkers).
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
引用されている仕様要件を conformance/tests/typeddicts_operations.py と比較し、その後、リンクされた議論と関連する PR を確認して、型チェッカーの異なる挙動を検討する。適合性テストと仕様のどちらを変更すべきかを解決する。完了とは、曖昧さが解消され、仕様とテストが一致している状態を指す。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation, testing
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100