Skip to content

Incorrect handling of kwargs when default values are present #5809

Closed
@takeda

Description

@takeda

I have a following code:

#! /usr/bin/env python

from typing import Any

def function(a, b, c=False, **kwargs):
	# type: (str, int, bool, **Any) -> None

	print "Got the following:", repr(a), repr(b), repr(c), repr(kwargs)

def main():
	# type: () -> None

	function('a', 2, **{'optional1': 1})

if __name__ == '__main__':
	main()

When I run it it produces this result:

$ ./test.py
Got the following: 'a' 2 False {'optional1': 1}

It looks like mypy thinks that the kwargs were passed as argument c which is incorrect:

$ ../py37/bin/mypy --python-executable ../py27/bin/python test.py
test.py:13: error: Argument 3 to "function" has incompatible type "**Dict[str, int]"; expected "bool"

The mypy version is 0.641

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions