-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
TypeVar not compatible with object #13689
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
Comments
Your code sample is incomplete, but that does look like an invariance problem. If |
One day I'll get my head round covariance properly. :P After making the TypeVar covariant, I still have one more error in:
That seems pretty much the same to me as the previous problem. I'll have the real code up in a PR in a couple of days, if it's useful to look at. |
The variance you set there doesn't do anything. What matters is how Task is declared in the stubs, and the TypeVar is invariant there: https://github.com/python/typeshed/blob/6ca80d340ef16714e61284df8338dac91479aa79/stdlib/asyncio/tasks.pyi#L268 |
OK, is that correct though? I'm looking at the list example at: https://mypy.readthedocs.io/en/stable/generics.html#variance-of-generics |
It does seem like we could make it covariant. We'd also have to make the base class |
Hmm asyncio.Future is mutable, if you made it covariant set_result would be unsound |
In order to keep code type safe and declare that my code will work with any type, I have used
object
. But, when trying to use aTypeVar
in another part of the code, it complains that it is incompatible withobject
.My code looks roughly like:
I'm getting:
I don't think it's an invariance problem..
The text was updated successfully, but these errors were encountered: