I think the boilerplate is this because generators are supposed to return instead of raise StopIteration
since Python 3.7.
def __iter__(self):
from itertools import count
try:
for i in count():
yield self[i]
except IndexError:
return