Simplest repro:
class BaseClass:
my_attr = () # type: tuple
class Subclass(BaseClass):
my_attr = None
Output:
testing.py: note: In class "Subclass":
testing.py:5: error: Need type annotation for variable
However, if None isn't the sole value but part of something else, this is likely not the desired behaviour. Consider this:
from typing import Tuple, Any
class BaseClass:
my_attr = ( ("", None), ) # type: Tuple[Tuple[str, Any]]
class Subclass(BaseClass):
my_attr = (
("one", set ),
("two", str ),
("three",None),
)
Output:
testing.py: note: In class "Subclass":
testing.py:8: error: Need type annotation for variable
Changing None for anything else, adding a # type: ignore comment on the ("one", set), line (but not on any other line of the assignment) silences the error. This is somewhat related to #1338 (and, to a lesser extent, #1032).
Simplest repro:
Output:
However, if
Noneisn't the sole value but part of something else, this is likely not the desired behaviour. Consider this:Output:
Changing
Nonefor anything else, adding a# type: ignorecomment on the("one", set),line (but not on any other line of the assignment) silences the error. This is somewhat related to #1338 (and, to a lesser extent, #1032).