You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are several issues about covariance, but I didn't find any discussion about __init__. Currently, mypy complains about this code:
fromtypingimportGeneric, TypeVarT_co=TypeVar('T_co', covariant=True)
classC(Generic[T_co]):
def__init__(self, x: T_co) ->None:
# Error: Cannot use a covariant type variable as a parameter
...
Although this is normal in general, I believe this should be allowed for __init__. Otherwise it would be difficult (if possible at all) to put something into a covariant (immutable) container on instantiation.
The text was updated successfully, but these errors were encountered:
Yeah, this should be allowed. Not sure if there are some additional edge cases related to __init__ we should handle differently once we allow this -- x.__init__(...) is already rejected, which is good.
There are several issues about covariance, but I didn't find any discussion about
__init__
. Currently, mypy complains about this code:Although this is normal in general, I believe this should be allowed for
__init__
. Otherwise it would be difficult (if possible at all) to put something into a covariant (immutable) container on instantiation.The text was updated successfully, but these errors were encountered: