When using type annotations in Python, what base type should we use for an argument that can either be a list
, tuple
, torch.Tensor
, numpy.ndarray
, etc.?
I would have expected the following to return true, since torch.Tensor
implements both __len__
and __getitem__
methods:
from collections.abc import Sequence
import torch
a = torch.tensor((3, 4, 5.0))
isinstance(a, Sequence)
>>> False