Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive with Dict passed to kwargs #6092

Closed
mthuurne opened this issue Dec 20, 2018 · 2 comments
Closed

False positive with Dict passed to kwargs #6092

mthuurne opened this issue Dec 20, 2018 · 2 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal

Comments

@mthuurne
Copy link
Contributor

When I run mypy on the following code:

from typing import Dict, Mapping

def f(*vargs: int, **kwargs: object) -> None:
	pass

d = {} # type: Dict[str, object]
f(**d)

m = {} # type: Mapping[str, object]
f(**m)

It reports:

7: error: Argument 1 to "f" has incompatible type "**Dict[str, object]"; expected "int"

Line 7 contains f(**d).

I don't understand why mypy expects int as the type of an argument passed using **: as far as I know, there is no way for a value passed using ** to be captured by an argument declared with *. Even if the passed map contains a key named vargs, its value would still end up in kwargs.

Note that arguments passed with ** are not positional, so the error message stating "Argument 1" is either poorly worded or perhaps the result of the same problem that causes the false positive.

What is confusing to me is that this false positive only occurs if I pass a Dict, not a Mapping. However, Python will create a new dictionary instance for kwargs in either case, so only the key and value types of the expression after ** should matter, I think, not the mapping type.

I'm using mypy 0.650 with Python 3.6.5.

@JukkaL JukkaL added bug mypy got something wrong priority-1-normal false-positive mypy gave an error on correct code labels Dec 20, 2018
@JukkaL
Copy link
Collaborator

JukkaL commented Dec 20, 2018

This is clearly a false positive. Thanks for reporting this!

The bug has apparently been around for a long time.

@ilevkivskyi
Copy link
Member

The bug has apparently been around for a long time.

Yes, I think this is a duplicate of #1969

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal
Projects
None yet
Development

No branches or pull requests

3 participants