Similar to #734, but for attributes. In a covariant class an instance attribute with type List[T] would not be valid, since List is invariant.
I wonder if theres a way to word the error message here so it would be the same as #734?
Hmm.. can't come up with a good common message right now. Why not just come up with a separate message for attributes?
Also, assignment to a covariant attribute should be rejected. There doesn't seem to be issue for that.
Am I correct in thinking that an example of this issue is:
from typing import TypeVar, Generic T = TypeVar("T", covariant=True) class Foo(Generic[T]): foo: T a: Foo[int] = Foo() b: Foo[object] = a b.foo = "sus" a.foo + 1 # no mypy error, runtime error
Activity
jhance commented on Oct 11, 2015
I wonder if theres a way to word the error message here so it would be the same as #734?
JukkaL commented on Oct 12, 2015
Hmm.. can't come up with a good common message right now. Why not just come up with a separate message for attributes?
JukkaL commented on Oct 12, 2015
Also, assignment to a covariant attribute should be rejected. There doesn't seem to be issue for that.
KotlinIsland commented on Feb 2, 2023
Am I correct in thinking that an example of this issue is: