Skip to content

Commit

Permalink
Don't map actual **kwargs to formal *args (#6096)
Browse files Browse the repository at this point in the history
The fix was originally proposed by @elazarg.

Fixes #1969.
  • Loading branch information
JukkaL authored Dec 20, 2018
1 parent 18b3cbd commit d61babb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mypy/argmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ def map_actuals_to_formals(actual_kinds: List[int],
no_certain_match = (
not formal_to_actual[fi]
or actual_kinds[formal_to_actual[fi][0]] == nodes.ARG_STAR)
if ((formal_names[fi] and no_certain_match)
or formal_kinds[fi] == nodes.ARG_STAR2):
if ((formal_names[fi]
and no_certain_match
and formal_kinds[fi] != nodes.ARG_STAR) or
formal_kinds[fi] == nodes.ARG_STAR2):
formal_to_actual[fi].append(ai)
return formal_to_actual

Expand Down
18 changes: 18 additions & 0 deletions test-data/unit/check-kwargs.test
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,21 @@ class A:
tmp/m.py:1: error: Unsupported operand types for + ("int" and "str")
main:2: error: Unexpected keyword argument "x" for "A"
tmp/m.py:3: note: "A" defined here

[case testStarArgsAndKwArgsSpecialCase]
from typing import Dict, Mapping

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

def g(arg: int = 0, **kwargs: object) -> None:
pass

d = {} # type: Dict[str, object]
f(**d)
g(**d) # E: Argument 1 to "g" has incompatible type "**Dict[str, object]"; expected "int"

m = {} # type: Mapping[str, object]
f(**m)
g(**m) # TODO: Should be an error
[builtins fixtures/dict.pyi]

0 comments on commit d61babb

Please sign in to comment.