from what I see, overriding an attribute with an incompatible type (which can lead to unsoundness) does not produce any kind of warning with mypy:
class Base:
attr = "foo"
def f(self) -> str:
return self.attr
class Derived(Base):
attr = 42
d = Derived()
reveal_type(d.f())
The code above shows that mypy thinks that the d.f() expression is a string, while it's actually an int. Shouldn't this kind of redefinitions be forbidden?
from what I see, overriding an attribute with an incompatible type (which can lead to unsoundness) does not produce any kind of warning with mypy:
The code above shows that mypy thinks that the
d.f()expression is a string, while it's actually an int. Shouldn't this kind of redefinitions be forbidden?