Description
If you consider bad error messages a bug, it is a bug. Otherwise, it is a feature request.
The following code sample is wrong because name
is not optional. Defining name
's value in MyImplementation or its constructor would fix this code.
from typing import Type, Protocol
class MyProtocol(Protocol):
name: str
class MyImplementation(MyProtocol):
pass
foo: Type[MyProtocol] = MyImplementation
However, running mypy from master or 0.770 produces an error which is very challenging to debug:
main.py:9: error: Can only assign concrete classes to a variable of type "Type[MyProtocol]"
Ideally, mypy would tell me the underlying problem. In this case, I took nearly a whole day of experimenting to fix it, ultimately needing to delete code until I got the error message to change. It would be ideal if mypy could say "and it is not concrete because name
is not defined statically or in __init__
." or something.
-
What are the versions of mypy and Python you are using?
mypy 0.770, python 3.8, yes it persists on master -
What are the mypy flags you are using? (For example --strict-optional)
This behavior seems unchanged by flags.