Skip to content

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

Open
@tusharsadhwani

Description

@tusharsadhwani

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions