Not quite. Here is an example how to use the internal targets attribute to filter out samples and create a Subset with only one class:
class MyDataset(Dataset):
    def __init__(self):
        self.data = torch.randn(100, 1)
        self.targets = torch.randint(0, 2, (100,))
        
    def __getitem__(self, index):
        x = self.data[index]
        y = self.targets[index]
        return x, y
    
    def __len__(self):
        return len(self.data)

dataset = MyDataset()
print(dataset.targets.unique(return_counts=True))
> (tensor([0, 1]), tensor([55, 45]))

# Filter out class1 and get indices for all samples corresponding to class1
idx = (dataset.targets == 1).nonzero()
print('{} class1 samples found'.format(len(idx)))
> 45 class1 samples found

dataset_class1 = Subset(dataset, indices=idx)
loader = DataLoader(dataset_class1)

for data, target in loader:
    print(target)

> tensor([[1]])
  tensor([[1]])
  tensor([[1]])
  ..