python / python/mypy

False positive with splat and explicit kwarg

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

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

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

説明

Bug Report

Mypy reports multiple values for a kwarg if args are given via splat and the kwarg is explicitly set.

To Reproduce

def foo(x: int, y: int, z: str) -> None:
    print(x, y, z)

args = [1, 2]
foo(*args, z="...")

Expected Behavior

Mypy should not report any problems.

Actual Behavior

mypysandbox.py:5: error: "foo" gets multiple values for keyword argument "z"  [misc]
mypysandbox.py:5: error: Argument 1 to "foo" has incompatible type "*list[int]"; expected "str"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

$ mypy --version
mypy 1.19.1 (compiled: yes)
$ python --version
Python 3.12.12

Mypy config from pyproject.toml:

[tool.mypy]
strict = true
allow_redefinition =  true

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

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

はじめの一歩

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

調査の方向性

issue にある最小限の Python 再現コードから始め、展開されたリストの後に明示的なキーワード引数が続く場合の mypy の処理を比較します。動作を確認する際は pyproject.toml の厳格な設定を使用します。完了とは、重複キーワードや互換性のない型のエラーを含め、例が診断を一切生成しないことを意味します。

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

評価

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

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

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