python / python/mypy

The different type (`str`) of unpacked inner dictionary items from the type (`int`) of outer dictionary items gets error

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

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

bug topic-type-context
主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

説明

*Memo:

  • mypy test.py
  • Python 3.14.0
  • mypy 1.19.1

The different type (str) of unpacked inner list items from the type (int) of outer list items doesn't get error as shown below:

v = [0, 1, *['a', 'b']] # No error

The different type (str) of unpacked inner dictionary items from the type (int) of outer dictionary items gets the error as shown below:

v = {0: 1, **{'a':'b'}} # Error

error: Cannot infer value of type parameter "KT" of

In additioin, if the types of keys in an inter and outer dictionary are the same, error doesn't occur as shown below:

v1 = {0: 1, **{2:'b'}}
v2 = {'0': 1, **{'a':'b'}}
# No error

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

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

はじめの一歩

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

調査の方向性

test.py の最小限の例から始め、Python 3.14.0 で mypy を実行して、リストと辞書のアンパックに対する診断結果の違いを再現します。示されている辞書のケースについて型推論の経路を追跡し、対象を絞った回帰テストを追加または更新します。既存の同じキー型のケースを退行させることなく、意図した動作が一貫してカバーされれば完了です。

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

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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