I'm wondering if it's possible to make a class object iterable in Python (ie. a subclass of type
, NOT an instance of a class).
I've tried the following code:
class Foo:
@classmethod
def __iter__(cls):
yield 1
print(next(Foo.__iter__())) # prints 1
print(next(iter(Foo))) # TypeError: 'type' object is not iterable