-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
priority-1-normaltopic-inheritanceInheritance and incompatible overridesInheritance and incompatible overrides
Description
Covariant overriding of attributes is allowed though it's clearly unsafe. Example:
class A:
x: float
class B(A):
x: int # no error, though unsafe
def f(a: A) -> None:
a.x = 1.1
b = B()
f(b)
b.x # float at runtime, though declared as int
Mypy should reject x: int
in B
. If this is actually what the programmer intended, they can use # type: ignore
.
KotlinIsland, DetachHead, lemon24, andreivasiliu, LeeeeT and 8 more
Metadata
Metadata
Assignees
Labels
priority-1-normaltopic-inheritanceInheritance and incompatible overridesInheritance and incompatible overrides