The method __getitem__() for a sequence (such as a list) can return a single item, or a sequence of items. For example, given the function decoration below:
def __getitem__(self, index) -> Union[Product, Generator[Product, None, None]]:
return super(Products, self).__getitem__(index)
Example usage:
i1 = 34
for product in products[i1:]:
print(product.name)
I believe Union[Product, Generator[Product, None, None]] to be correct, but PyCharm flags this as improper. Am I misusing the typing library, or is this a PyCharm issue?
Thanks!