python / python/mypy

Errors for incorrect type on `**kwargs` should give the name of the argument

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

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

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

説明

Bug Report

In case of **kwargs being passed to an overloaded function, one issue gets raised for every overload of that function. This problem is not present when passing a regular incompatible type to that overloaded function, eg. int

To Reproduce

import json
from typing import Any

def load(data: str, **kwargs: object) -> Any:
    return json.loads(data, **kwargs)

Gist: https://mypy-play.net/?mypy=master&python=3.11&gist=8d7f8bb50c5f9022469b59ec127df614

The bug won't reproduce for eg. if **kwargs: object was replaced with x: object.

Expected Behavior

Single issue being raised.

Actual Behavior

$ mypy asd.py
asd.py:5: error: Argument 2 to "loads" has incompatible type "**dict[str, object]"; expected "type[JSONDecoder] | None"  [arg-type]
asd.py:5: error: Argument 2 to "loads" has incompatible type "**dict[str, object]"; expected "Callable[[dict[Any, Any]], Any] | None"  [arg-type]
asd.py:5: error: Argument 2 to "loads" has incompatible type "**dict[str, object]"; expected "Callable[[str], Any] | None"  [arg-type]
asd.py:5: error: Argument 2 to "loads" has incompatible type "**dict[str, object]"; expected "Callable[[list[tuple[Any, Any]]], Any] | None"  [arg-type]
Found 4 errors in 1 file (checked 1 source file)

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

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

はじめの一歩

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

調査の方向性

まず、提供されている mypy-play の再現コードまたは示されている mypy asd.py コマンドを実行し、その後、オーバーロードされた呼び出しが **kwargs の診断をどのように処理するかを追跡します。完了条件は、例がオーバーロードごとに 1 つのエラーを報告するのではなく、互換性のない引数のエラーを 1 つ報告し、この動作を対象とするリグレッションテストでカバーされていることです。

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

評価

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

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

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