python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.33k stars 2.81k forks source link

Dict unpacking type checks don't consider **kwargs #17642

Open dinatamas opened 2 months ago

dinatamas commented 2 months ago

Bug Report:

In the below example (playground gist), mypy behaves differently with respect to **kwargs:

def func(x: bool = False, **kwargs):
    print(x, kwargs)

# This is accepted by mypy.
func(y="y")

# This is flagged by mypy.
data = {"y": "y"}
func(**data)

The error is Argument 1 to "func" has incompatible type "**dict[str, str]"; expected "bool" [arg-type]. This is incorrect because the function has **kwargs, so the dict / function call should be considered type correct.

Your Environment:

153957 commented 2 days ago

Some related issues: