Dict comprehension from Iterable of Literal
オープン
まだ誰も着手していません。
bug
false-positive
priority-1-normal
topic-literal-types
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
Related to #7533
mypy 0.740, python 3.7.4, typing_extensions 3.7.4
dict comprehension won't recognize an Iterable of Literal as input.
Unlike in #7533, this is not limited to just tuples.
The dict constructor and dict.fromkeys have no problem.
from typing import Dict
from typing_extensions import Literal
T = Literal[1, 2, 3]
d: Dict[T, None]
d = {x: None for x in [1, 2, 3]}
# error: Key expression in dictionary comprehension has incompatible type "int"; expected type "Union[Literal[1], Literal[2], Literal[3]]"
d = dict(zip([1, 2, 3], [None, None, None])) # no error
d = dict.fromkeys([1, 2, 3]) # no error
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された Python 再現コードから始め、dict comprehension と、動作する dict constructor および dict.fromkeys のケースを比較します。mypy がリテラルキーを Dict[Literal[1, 2, 3], None] に割り当てる comprehension を、互換性のないキー式エラーなしで受け入れれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100