You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
I am inclined to call the behavior a bug, I'd expect no error, and both
A.a
andB.a
to be considered of typeList[int]
by mypy in the above code.Seems related to #3903
The text was updated successfully, but these errors were encountered: