for chunk in gen:
    yield chunk


class foobar(namedtuple('f', 'foo, bar')):
    pass
enc = MyEncoder()
for obj in (foobar('a', 1), ('a', 1), {'outer': foobar('x', 'y')}):
    print(enc.encode(obj))
{'foo': 'a', 'bar': 1}
['a', 1]
{'outer': {'foo': 'x', 'bar': 'y'}}
Сериализация Python namedtuple в json