python / python/typing

Discrepancy between spec and tests on indexing TypedDicts with non-literal variables

オープン
#2,053 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

topic: typing spec
主要言語
Python
スター
1.8k
フォーク
302
平均マージ
23時間
マージ済み PR(30日)
8

説明

Splitting issue from PR https://github.com/python/typing/pull/1978

Spec says that it should be generally rejected (ref)

A key that is not a literal should generally be rejected, since its value is unknown during type checking, and thus can cause some of the above violations.

But currently conformance tests do not reflect it.

https://github.com/python/typing/blob/2d88da2a407b556f5b52b4c6ad1bd659873bb9ac/conformance/tests/typeddicts_operations.py#L34-L38

So in theory to resolve this, either strictness should be reflected in conformance tests or spec should be amended allowing optional enforcement.

Related discussion - https://discuss.python.org/t/indexing-typeddict-with-a-non-literal-variable/88929

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

TypedDict operations spec セクションと、34-38 行目付近の conformance/tests/typeddicts_operations.py から始め、次に PR 1978 とリンクされた議論を読んでください。conformance tests が非リテラルによるインデックス付けを拒否すべきか、それとも仕様で任意の適用を許可すべきかを判断してください。仕様と conformance tests が合意された動作を一貫して記述していれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
documentation, testing
issue の種類
ドキュメント
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。