python / python/mypy

mypy flags "overlap between argument names and ** TypedDict items" with total=False

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

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

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

説明

Bug Report

mypy complains about explicit kwargs of a function appearing in the Unpacked TypedDict used for the ** parameter, even if the TypedDict is total=False.

To Reproduce

from typing import TypedDict, Unpack


class Opts(TypedDict, total=False):
    verbose: bool
    other: str


def do_a(*, verbose: bool = False, **_kwargs: Unpack[Opts]) -> None:
    pass


def do_b(**kwargs: Unpack[Opts]) -> None:
    pass


def do_thing(cmd: str, **kwargs: Unpack[Opts]) -> None:
    match cmd:
        case 'a':
            do_a(**kwargs)

        case 'b':
            do_b(**kwargs)

https://mypy-play.net/?mypy=latest&python=3.12&gist=a7836435f32a3fab9c3e671b73897370

Expected Behavior

I expect that this should be completely fine. Yes, verbose might end up being "stolen" away from the **kwargs in do_a() but that's quite fine, since total=False there anyway. There is no promise/expectation that verbose will be included.

Actual Behavior

main.py:9: error: Overlap between argument names and ** TypedDict items: "verbose" [misc]

Your Environment

I'm running on Fedora 42 (mypy 1.15.0 (compiled: no)), but the playground gets exactly the same error.

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

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

はじめの一歩

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

調査の方向性

main.py の最小再現例から始めるか、リンクされている mypy playground で実行し、9 行目の重複診断を確認します。Unpack’ed total=False TypedDict に対して「Overlap between argument names and ** TypedDict items」と報告する mypy の型チェックのエントリーポイントを追跡します。完了条件は、他の型付けの動作のチェックを維持したまま、再現例でこのエラーが報告されなくなることです。

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

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
52/100

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

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