python / python/mypy

Passing `**dict(...)` to `functools.partial` confuses mypy

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

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

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

説明

Bug Report

Something like partial(func, **dict(a=1)) confuses mypy which seems to expect the dictionary keys to contain all the arguments to func, leading to errors if positional arguments are not specified (see this playground / gist), or if only a few arguments are specified and later more as passed to partial's return value (see this playground / gist).

Expected Behavior

I realise that mypy cannot know what ends up in an untyped dictionary, but it should maybe just give up in this case.

Actual Behavior

See gist.

Your Environment

  • Mypy version used: mypy 1.15.0 (compiled: yes), but also master while using the playground
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10.1, but also 3.13 while using the playground

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

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

はじめの一歩

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

調査の方向性

まず、リンク先の mypy playground と gist にある2つの例を、mypy 1.15.0 と master で再現します。functools.partial がアンパックされた辞書をどのように処理するかを追跡し、その後、報告されたケースで誤った診断が生成されなくなっている一方で、有効な partial 呼び出しは引き続きチェックされることを確認します。

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

評価

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

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

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