Repository: python/mypy

Issue:
mypy --strict has misleading suggestion for Callable
<!--
  If you're new to mypy and you're not sure whether what you're experiencing is a mypy bug, please see the "Question and Help" form
  instead.
  Please also consider:

  - checking our common issues page: https://mypy.readthedocs.io/en/stable/common_issues.html
  - searching our issue tracker: https://github.com/python/mypy/issues to see if
    it's already been reported
  - asking on gitter chat: https://gitter.im/python/typing
-->

**Bug Report**

<!--
Note: If the problem you are reporting is about a specific library function, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues
-->

It's not a big issue, not sure if you should even qualify it as a bug but I fought it fitted better than other categories.
When in strict mode, it gives a suggestion that is actually not valid in strict mode.

**To Reproduce**

Running `mypy --strict` on this code
```
from typing import Callable

def my_function(callback: Callable[...]) -> None:
    callback()
```
gives the following error message:
```
$ mypy callable_test.py --strict
callable_test.py:3: error: Please use "Callable[[<parameters>], <return type>]" or "Callable"        
Found 1 error in 1 file (checked 1 source file)
```

However, changing the code to use the second suggestion of using `Callable`:
```
from typing import Callable

def my_function(callback: Callable) -> None:
    callback()
```
gives a new error message:

```
$ mypy callable_test.py --strict
callable_test.py:3: error: Missing type parameters for generic type "Callable"
Found 1 error in 1 file (checked 1 source file)
```

Running mypy in non-strict mode does not give this error. But if it is at all possible it would be nice to remove the second suggestion in strict mode (or turn it into `Callable[..., Any]`).

I got confused (didn't spot that I was missing an `Any` return value in my `Callable[...]` annotation) and kept switching back and forth wondering why the suggestion was not working. Which admittedly is my mistake. But it did bring to light for me that the suggestion is a bit misleading in this context.

I don't know if this is easily done or not, if it's a relatively minor fix I'd be willing to give it a crack.


Additional info:
```
$ mypy --version
mypy 0.902
```
```
$ python --version
Python 3.8.10
```



Discussion:
Encountering the same issue as mentioned by @frerikandriessen.

My versions of Python and mypy:

```
mypy 0.931
Python 3.7.1
```
The line of code creating the error message is here: https://github.com/python/mypy/blob/544d21a43762a526bdc53098a1fae87627d4a454/mypy/typeanal.py#L816

I think we just need to make the error message slightly different if `--disallow-any-generics` is set to `True` (this option is automatically set to `True` if mypy is being run with `--strict`). To find out if `--disallow-any-generics` is set to `True`, you should be able to check whether `self.options.disallow_any_generics` is `True` or `False`.

Resolving patch:
diff --git a/mypy/typeanal.py b/mypy/typeanal.py
--- a/mypy/typeanal.py
+++ b/mypy/typeanal.py
@@ -813,7 +813,10 @@ def analyze_callable_type(self, t: UnboundType) -> Type:
                     return AnyType(TypeOfAny.from_error)
                 ret = maybe_ret
         else:
-            self.fail('Please use "Callable[[<parameters>], <return type>]" or "Callable"', t)
+            if self.options.disallow_any_generics:
+                self.fail('Please use "Callable[[<parameters>], <return type>]"', t)
+            else:
+                self.fail('Please use "Callable[[<parameters>], <return type>]" or "Callable"', t)
             return AnyType(TypeOfAny.from_error)
         assert isinstance(ret, CallableType)
         return ret.accept(self)


Test patch: