From 4efb7b1830a4e4fc2ce6992c3eda215c8404c542 Mon Sep 17 00:00:00 2001 From: Purna Chandra Mansingh Date: Sun, 20 Feb 2022 22:56:06 +0530 Subject: [PATCH 1/3] Improve the Argument must be a mapping error message --- mypy/messages.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 406237783cf1..d58730d3748a 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -953,11 +953,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: From 1c489de4787d91067f7ed382a5ffd7a64b5a8e2f Mon Sep 17 00:00:00 2001 From: Purna Chandra Mansingh Date: Sun, 27 Feb 2022 20:06:40 +0530 Subject: [PATCH 2/3] added test for testInvalidTypeForKeywordVarArg --- test-data/unit/check-kwargs.test | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test-data/unit/check-kwargs.test b/test-data/unit/check-kwargs.test index 7f0b8af3ba0e..e5600a9d169d 100644 --- a/test-data/unit/check-kwargs.test +++ b/test-data/unit/check-kwargs.test @@ -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] 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] From 69c89207821cc072a14f6e98c90f9c39d884423c Mon Sep 17 00:00:00 2001 From: Purna Chandra Mansingh Date: Sun, 27 Feb 2022 20:48:34 +0530 Subject: [PATCH 3/3] added test for testInvalidTypeForKeywordVarArg --- test-data/unit/check-kwargs.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-data/unit/check-kwargs.test b/test-data/unit/check-kwargs.test index e5600a9d169d..9f8de1265ee7 100644 --- a/test-data/unit/check-kwargs.test +++ b/test-data/unit/check-kwargs.test @@ -353,7 +353,7 @@ class A: pass # 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