@user_123454321 I thought so too. But it doesn’t stop at Index Error:
from torch.utils.data import Dataset

class NumbersDataset(Dataset):
    def __init__(self):
        self.samples = [1,2,3,4,5]

    def __len__(self):
        return 3

    def __getitem__(self, idx):
        print(f"Trying {idx}")
        if idx>3: raise IndexError
        return self.samples[idx]



dataset = NumbersDataset()

len(dataset), len(list(dataset))
>>> (3,5)

list(dataset)
>>> [1, 2, 3, 4, 5]