-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Under --strict-optional
, when inheriting from a generic base class applied to None, method implementations on the subclass can produce spurious errors like so:
$ cat /tmp/foo.py
from typing import Generic, TypeVar
T = TypeVar('T')
class Base(Generic[T]):
def f(self) -> T:
pass
class SubNone(Base[None]):
def f(self) -> None:
pass
class SubInt(Base[int]):
def f(self) -> int:
return 1
$ mypy /tmp/foo.py --strict-optional
/tmp/foo.py: note: In class "SubNone":
/tmp/foo.py:10: error: Return type of "f" incompatible with supertype "Base"
Note there's no error when the same thing is done with int
instead of None
. There's also no error without --strict-optional
.
This issue causes about 109 error messages when type-checking mypy itself under --strict-optional
, in various subclasses of NodeVisitor[None]
and TypeVisitor[None]
.
I haven't tried hard to reduce this repro -- it's possible that some of the elements of it are unnecessary.