-
Notifications
You must be signed in to change notification settings - Fork 149
Closed
Description
The documentation of flatten
states, that it works with any iterable. A python iterable in general isn't required to have a predefined length. So a call of len(iterable)
should be handled with the necessary care. Unfortunately, this doesn't happen in flatten
and fails with a TypeError
.
Reproducer:
from streamz import Stream
stream = Stream()
lst = stream.flatten().sink_to_list()
gen = (r for r in range(10))
stream.emit(gen)
File ~/.local/lib/python3.10/site-packages/streamz/core.py:1632, in flatten.update(self, x, who, metadata)
1630 L = []
1631 for i, item in enumerate(x):
-> 1632 if i == len(x) - 1:
1633 y = self._emit(item, metadata=metadata)
1634 else:
TypeError: object of type 'generator' has no len()
The loop should probably just emit the previous item, until it runs in a StopIteration
and then emit the last item together with the metadata. Or maybe even just sending the metadata together with the first item?
Metadata
Metadata
Assignees
Labels
No labels