Skip to content

False positive when a function accepts **kwargs after arguments with default values #954

Open
@MaigoAkisame

Description

@MaigoAkisame

Pyre Bug

Bug description

Pyre mistakenly reports an "incompatible parameter type [6]" error when a function's signature declares **kwargs after arguments with default values, and a caller tries to provide values for kwargs with a ** expansion.

Reproduction steps

Here's a minimal example:

def foo(a: int = 1, b: float = 2.0, c: bool = True, **kwargs: Any) -> None:
    pass

dic = {"key": "value", "foo": [1, 2, 3]}
foo(**dic)

Run pyre, and you'll get the following errors:

Incompatible parameter type [6]: In call `foo`, for 1st positional argument, expected `bool` but got `Union[List[int], str]`.
Incompatible parameter type [6]: In call `foo`, for 1st positional argument, expected `float` but got `Union[List[int], str]`.
Incompatible parameter type [6]: In call `foo`, for 1st positional argument, expected `int` but got `Union[List[int], str]`.

Apparently, pyre is matching the values in dic with the arguments a, b, and c.
Also, the word 1st in the error messages isn't always accurate: b and c are the 2nd and 3rd positional arguments.

Expected behavior

There should be no error, because the contents of dic should be matched with **kwargs.

Logs

N/A

Additional context

Maybe a duplicate of #242, but it's rather hard to read, and I'm not sure if I understand it.

Another Python type checker, mypy, has this bug, too. It has been reported repeatedly in the last 8 years (examples below), but hasn't been fixed yet.
python/mypy#8485 (reported by the same user as the issue above)
python/mypy#1969 (first report in 2016)
python/mypy#5382 (contains links to all similar reports)
python/mypy#8862

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions