Skip to content

Commit

Permalink
Improve the "Argument must be a mapping" error message (#12222)
Browse files Browse the repository at this point in the history
Fixes #12070
  • Loading branch information
purna135 committed Mar 2, 2022
1 parent 187f394 commit 26bfc63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 1 addition & 4 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,11 +954,8 @@ def invalid_keyword_var_arg(self, typ: Type, is_mapping: bool, context: Context)
if isinstance(typ, Instance) and is_mapping:
self.fail('Keywords must be strings', context)
else:
suffix = ''
if isinstance(typ, Instance):
suffix = ', not {}'.format(format_type(typ))
self.fail(
'Argument after ** must be a mapping{}'.format(suffix),
'Argument after ** must be a mapping, not {}'.format(format_type(typ)),
context, code=codes.ARG_TYPE)

def undefined_in_superclass(self, member: str, context: Context) -> None:
Expand Down
7 changes: 5 additions & 2 deletions test-data/unit/check-kwargs.test
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,15 @@ class A: pass
[builtins fixtures/dict.pyi]

[case testInvalidTypeForKeywordVarArg]
from typing import Dict
# flags: --strict-optional
from typing import Dict, Any, Optional
def f(**kwargs: 'A') -> None: pass
d = None # type: Dict[A, A]
d = {} # type: Dict[A, A]
f(**d) # E: Keywords must be strings
f(**A()) # E: Argument after ** must be a mapping, not "A"
class A: pass
kwargs: Optional[Any]
f(**kwargs) # E: Argument after ** must be a mapping, not "Optional[Any]"
[builtins fixtures/dict.pyi]

[case testPassingKeywordVarArgsToNonVarArgsFunction]
Expand Down

0 comments on commit 26bfc63

Please sign in to comment.