-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Description
from typing import List
class A(object):
a = [] # type: List[int]
class B(A):
a = []
This pattern of declaring an attribute in a superclass and then overriding the value with empty list or dict is fairly common in my codebase. Therefore, when mypy forces me to annotate all the places where override happens, it is fairly painful.
% mypy ab.py
ab.py:7: error: Need type annotation for 'a' (hint: "a: List[<type>] = ...")
% mypy --py2 ab.py
ab.py:7: error: Need type comment for 'a' (hint: "a = ... # type: List[<type>]")
I am inclined to call the behavior a bug, I'd expect no error, and both A.a and B.a to be considered of type List[int] by mypy in the above code.
% mypy --version
mypy 0.720
Seems related to #3903
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels