-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check attributes for variance violations #735
Labels
Comments
Closed
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. |
JukkaL
added
topic-type-variables
priority-1-normal
bug
mypy got something wrong
and removed
feature
labels
May 18, 2018
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: