diff --git a/mypy/typeanal.py b/mypy/typeanal.py index 98e37bd0aa40..bd0f684653b2 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -944,9 +944,13 @@ def analyze_callable_type(self, t: UnboundType) -> Type: ) if maybe_ret is None: # Callable[?, RET] (where ? is something invalid) - # TODO(PEP612): change error to mention paramspec, once we actually have some - # support for it - self.fail('The first argument to Callable must be a list of types or "..."', t) + self.fail( + 'The first argument to Callable must be a ' + 'list of types, parameter specification, or "..."', t) + self.note( + 'See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas', # noqa: E501 + t + ) return AnyType(TypeOfAny.from_error) ret = maybe_ret else: @@ -1180,6 +1184,10 @@ def anal_type(self, t: Type, nested: bool = True, *, allow_param_spec: bool = Fa and analyzed.flavor == ParamSpecFlavor.BARE): if analyzed.prefix.arg_types: self.fail('Invalid location for Concatenate', t) + self.note( + 'You can use Concatenate as the first argument to Callable', + t + ) else: self.fail(f'Invalid location for ParamSpec "{analyzed.name}"', t) self.note( diff --git a/test-data/unit/check-parameter-specification.test b/test-data/unit/check-parameter-specification.test index 28b08aa7122f..4dae32978263 100644 --- a/test-data/unit/check-parameter-specification.test +++ b/test-data/unit/check-parameter-specification.test @@ -25,7 +25,8 @@ def foo1(x: Callable[P, int]) -> Callable[P, str]: ... def foo2(x: P) -> P: ... # E: Invalid location for ParamSpec "P" \ # N: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]' -def foo3(x: Concatenate[int, P]) -> int: ... # E: Invalid location for Concatenate +def foo3(x: Concatenate[int, P]) -> int: ... # E: Invalid location for Concatenate \ + # N: You can use Concatenate as the first argument to Callable def foo4(x: List[P]) -> None: ... # E: Invalid location for ParamSpec "P" \ # N: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]' diff --git a/test-data/unit/semanal-errors.test b/test-data/unit/semanal-errors.test index 14bc24f03a7b..a1ff4ec1c3e7 100644 --- a/test-data/unit/semanal-errors.test +++ b/test-data/unit/semanal-errors.test @@ -867,7 +867,8 @@ x = None # type: Callable[int, str] y = None # type: Callable[int] z = None # type: Callable[int, int, int] [out] -main:2: error: The first argument to Callable must be a list of types or "..." +main:2: error: The first argument to Callable must be a list of types, parameter specification, or "..." +main:2: note: See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas main:3: error: Please use "Callable[[], ]" or "Callable" main:4: error: Please use "Callable[[], ]" or "Callable"