Skip to content

Commit a823c6c

Browse files
committed
Don't map actual **kwargs to formal *args
The fix was originally proposed by @elazarg. Fixes #1969.
1 parent 18b3cbd commit a823c6c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mypy/argmap.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ def map_actuals_to_formals(actual_kinds: List[int],
8181
no_certain_match = (
8282
not formal_to_actual[fi]
8383
or actual_kinds[formal_to_actual[fi][0]] == nodes.ARG_STAR)
84-
if ((formal_names[fi] and no_certain_match)
85-
or formal_kinds[fi] == nodes.ARG_STAR2):
84+
if ((formal_names[fi]
85+
and no_certain_match
86+
and formal_kinds[fi] != nodes.ARG_STAR) or
87+
formal_kinds[fi] == nodes.ARG_STAR2):
8688
formal_to_actual[fi].append(ai)
8789
return formal_to_actual
8890

test-data/unit/check-kwargs.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,16 @@ class A:
403403
tmp/m.py:1: error: Unsupported operand types for + ("int" and "str")
404404
main:2: error: Unexpected keyword argument "x" for "A"
405405
tmp/m.py:3: note: "A" defined here
406+
407+
[case testStarArgsAndKwArgsSpecialCase]
408+
from typing import Dict, Mapping
409+
410+
def f(*vargs: int, **kwargs: object) -> None:
411+
pass
412+
413+
d = {} # type: Dict[str, object]
414+
f(**d)
415+
416+
m = {} # type: Mapping[str, object]
417+
f(**m)
418+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)