Description
Bug Report
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