TypedDict item insertion support
オープン
まだ誰も着手していません。
feature
priority-1-normal
topic-typed-dict
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
- Are you reporting a bug, or opening a feature request?
Feature request - Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
Currently I can't insert items into TypedDict even after explicit check for a defined key:
from mypy_extensions import TypedDict
GroupDataDict = TypedDict(
'GroupDataDict', {"children": str,
"vars": str,
"hosts": str}, total=False
)
test_group: GroupDataDict = {}
key = "children"
if key in ("children", "vars"):
test_group[key] = "a"
if key not in ["children", "vars"]:
raise ValueError("")
test_group[key] = "b"
print(test_group)
- What is the actual behavior/output?
-> % mypy typeddict_insertion.py
typeddict_insertion.py:12: error: TypedDict key must be a string literal; expected one of ('children', 'vars', 'hosts')
typeddict_insertion.py:16: error: TypedDict key must be a string literal; expected one of ('children', 'vars', 'hosts')
- What is the behavior/output you expect?
No error - What are the versions of mypy and Python you are using?
mypy 0.620 + Python 3.7 - Do you see the same issue after installing mypy from Git master?
I haven't tried - What are the mypy flags you are using? (For example --strict-optional)
[mypy]
python_version = 3.7
check_untyped_defs = True
disallow_any_generics = True
disallow_untyped_calls = True
ignore_errors = False
ignore_missing_imports = True
strict_optional = True
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された TypedDict の例を現在の mypy バージョンで実行し、TypedDict のキー式がどのようにチェックされるかを調べます。キーを有効な TypedDict 名に制限する明示的なチェックによって、示されている代入がエラーなしで許可され、無効なキーは引き続き拒否されるようになったら作業は完了です。両方のケースに対する焦点を絞ったテストを追加または更新してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100