Skip to content

Commit 26bfc63

Browse files
authored
Improve the "Argument must be a mapping" error message (#12222)
Fixes #12070
1 parent 187f394 commit 26bfc63

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

mypy/messages.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,11 +954,8 @@ def invalid_keyword_var_arg(self, typ: Type, is_mapping: bool, context: Context)
954954
if isinstance(typ, Instance) and is_mapping:
955955
self.fail('Keywords must be strings', context)
956956
else:
957-
suffix = ''
958-
if isinstance(typ, Instance):
959-
suffix = ', not {}'.format(format_type(typ))
960957
self.fail(
961-
'Argument after ** must be a mapping{}'.format(suffix),
958+
'Argument after ** must be a mapping, not {}'.format(format_type(typ)),
962959
context, code=codes.ARG_TYPE)
963960

964961
def undefined_in_superclass(self, member: str, context: Context) -> None:

test-data/unit/check-kwargs.test

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,15 @@ class A: pass
350350
[builtins fixtures/dict.pyi]
351351

352352
[case testInvalidTypeForKeywordVarArg]
353-
from typing import Dict
353+
# flags: --strict-optional
354+
from typing import Dict, Any, Optional
354355
def f(**kwargs: 'A') -> None: pass
355-
d = None # type: Dict[A, A]
356+
d = {} # type: Dict[A, A]
356357
f(**d) # E: Keywords must be strings
357358
f(**A()) # E: Argument after ** must be a mapping, not "A"
358359
class A: pass
360+
kwargs: Optional[Any]
361+
f(**kwargs) # E: Argument after ** must be a mapping, not "Optional[Any]"
359362
[builtins fixtures/dict.pyi]
360363

361364
[case testPassingKeywordVarArgsToNonVarArgsFunction]

0 commit comments

Comments
 (0)