python / python/mypy

False Positive when TypedDict instance used as base __map for new instances?

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

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

bug
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Bug Report

Why doesn't mypy accept another TypedDict as the __map argument when defining a new instance as shown below? It seems perfectly valid to me, but I could be missing something.

To Reproduce

Save the following as test_mypy.py and ask mypy to check it:

from typing import TypedDict


class MyTypedDict(TypedDict):
    attr1: str
    attr2: str
    attr3: str


MY_BASE_DICT = MyTypedDict(
    attr1="testing",
    attr2="typeddict",
    attr3="inheritance",
)

new_typed_dict = MyTypedDict(MY_BASE_DICT, attr1="failing")

assert " ".join(new_typed_dict.values()) == "failing typeddict inheritance"

Expected Behavior

> mypy test_mypy.py
Success: no issues found in 1 source file

Actual Behavior

> mypy test_mypy.py
test_mypy.py:17: error: Expected keyword arguments, {...}, or dict(...) in TypedDict constructor  [misc]
Found 1 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: v1.8.0 (command line call) and v1.6.1 (integrated vscode extension)
  • Mypy command-line flags: none required although I'm typically adding --check-untyped-defs --implicit-optional
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: 3.10.6

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

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

はじめの一歩

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

調査の方向性

例を test_mypy.py として保存し、mypy test_mypy.py を実行して報告を再現します。MY_BASE_DICT を拒否する TypedDict コンストラクターのチェックを追跡し、その後、キーワードによる上書きを維持したまま TypedDict インスタンスをベースマッピングとして使用する回帰テストを追加します。例が [misc] エラーなしで成功すれば完了です。

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

評価

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

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

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