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
I want define a generic class which is covariant with its type parameter, but mypy claims that covariant type parameter in instance method definition is not allowed.
fromtypingimportGeneric, List, TypeVarT=TypeVar("T", covariant=True)
classGenericClass(Generic[T]):
def__init__(self) ->None:
self.list: List[T] = []
defprint(self, arg: T) ->None: # <<< mypy raises error on the "T"; Cannot use a covariant type variable as a parameterself.list.append(arg)
print(self.list)
if__name__=="__main__":
g: GenericClass[int] =GenericClass()
g.print(1)
Is there any solution to get around this?
qpwo, failable, eigenein, Miku-039, fzyzcjy and 4 more