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

Incompatible type when expanded-dict-as-kwargs used in named default argument position #5834

Closed
briancurtin opened this issue Oct 24, 2018 · 1 comment

Comments

@briancurtin
Copy link
Member

(Please feel free to re-title this as necessary if I've misunderstood the short explanation)

I believe I've found a bug that lies somewhere between a named default argument and keyword arguments that follow it, but specifically in the case where the kwargs come from a ** expanded dict.

Here is a minimal example of the function causing this:

from typing import List

def fn(x: str, y: bool=True, **kwargs: List[str]) -> None:
    print(x, y, kwargs)

Here is an example of some calls to this function:

fn("hello", y=False)  # ok
fn("hello", kw1=["a", "b"], kw2=["c", "d"])  # ok
...
kwargs = {"kw1": ["a", "b"], "kw2": ["c", "d"]}
fn("hello", **kwargs)  # functionally same as above, but error

On the third fn call I'll end up receiving the following error when running mypy on that code:

error: Argument 2 to "fn" has incompatible type "**Dict[str, List[str]]"; expected "bool"

My general expectation was that this would work fine. This is seen while running with the following (with no special flags to the mypy run):

$ mypy --version
mypy 0.641
$ python3 --version
Python 3.7.0+

I've also tried with master (mypy 0.650+dev.e09e72775bfeb622e67cab7d5eae0f12ef4adefa) and the behavior is the same.

@ilevkivskyi
Copy link
Member

Thanks for reporting! This is a duplicate of #1969 (which is pretty old).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants