From 4d481f50aacf4b8651a310a57c8a2b7d6b736b1c Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 29 Sep 2022 18:35:49 -0700 Subject: [PATCH 1/2] Improve error message for `--strict-concatenate` Resolves #13711, resolves #13429 --- mypy/messages.py | 4 ++-- test-data/unit/check-parameter-specification.test | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 8f2cbbd16628..5221d395793b 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -791,8 +791,8 @@ def maybe_note_concatenate_pos_args( if names: missing_arguments = '"' + '", "'.join(names) + '"' self.note( - f'This may be because "{original_caller_type.name}" has arguments ' - f"named: {missing_arguments}", + f'This is likely because "{original_caller_type.name}" has arguments ' + f"named: {missing_arguments}. Consider marking them positional-only", context, code=code, ) diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index b5b851a581ce..443a33a82ef4 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -530,7 +530,7 @@ reveal_type(transform(bar)) # N: Revealed type is "def (builtins.str, *args: bui def expects_int_first(x: Callable[Concatenate[int, P], int]) -> None: ... @expects_int_first # E: Argument 1 to "expects_int_first" has incompatible type "Callable[[str], int]"; expected "Callable[[int], int]" \ - # N: This may be because "one" has arguments named: "x" + # N: This is likely because "one" has arguments named: "x". Consider marking them positional-only def one(x: str) -> int: ... @expects_int_first # E: Argument 1 to "expects_int_first" has incompatible type "Callable[[NamedArg(int, 'x')], int]"; expected "Callable[[int, NamedArg(int, 'x')], int]" @@ -598,7 +598,7 @@ f2(lambda x: 42)(42, x=42) main:10: error: invalid syntax; you likely need to run mypy using Python 3.8 or newer [out version>=3.8] main:17: error: Incompatible return value type (got "Callable[[Arg(int, 'x'), **P], R]", expected "Callable[[int, **P], R]") -main:17: note: This may be because "result" has arguments named: "x" +main:17: note: This is likely because "result" has arguments named: "x". Consider marking them positional-only [case testNonStrictParamSpecConcatenateNamedArgs] # flags: --python-version 3.8 From 395e5c311a7bcf4fbfe9d2a89591f750a056faf0 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 29 Sep 2022 18:38:59 -0700 Subject: [PATCH 2/2] more wording --- mypy/messages.py | 4 ++-- test-data/unit/check-parameter-specification.test | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 5221d395793b..49c39fa9405b 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -791,8 +791,8 @@ def maybe_note_concatenate_pos_args( if names: missing_arguments = '"' + '", "'.join(names) + '"' self.note( - f'This is likely because "{original_caller_type.name}" has arguments ' - f"named: {missing_arguments}. Consider marking them positional-only", + f'This is likely because "{original_caller_type.name}" has named arguments: ' + f"{missing_arguments}. Consider marking them positional-only", context, code=code, ) diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index 443a33a82ef4..f91995379b61 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -530,7 +530,7 @@ reveal_type(transform(bar)) # N: Revealed type is "def (builtins.str, *args: bui def expects_int_first(x: Callable[Concatenate[int, P], int]) -> None: ... @expects_int_first # E: Argument 1 to "expects_int_first" has incompatible type "Callable[[str], int]"; expected "Callable[[int], int]" \ - # N: This is likely because "one" has arguments named: "x". Consider marking them positional-only + # N: This is likely because "one" has named arguments: "x". Consider marking them positional-only def one(x: str) -> int: ... @expects_int_first # E: Argument 1 to "expects_int_first" has incompatible type "Callable[[NamedArg(int, 'x')], int]"; expected "Callable[[int, NamedArg(int, 'x')], int]" @@ -598,7 +598,7 @@ f2(lambda x: 42)(42, x=42) main:10: error: invalid syntax; you likely need to run mypy using Python 3.8 or newer [out version>=3.8] main:17: error: Incompatible return value type (got "Callable[[Arg(int, 'x'), **P], R]", expected "Callable[[int, **P], R]") -main:17: note: This is likely because "result" has arguments named: "x". Consider marking them positional-only +main:17: note: This is likely because "result" has named arguments: "x". Consider marking them positional-only [case testNonStrictParamSpecConcatenateNamedArgs] # flags: --python-version 3.8