Skip to content

Commit

Permalink
Cover slice edge cases
Browse files Browse the repository at this point in the history
- slice(0)
- slice(start, start)
- slice(start, start, y)
  • Loading branch information
gonzaponte committed Feb 15, 2024
1 parent 868235c commit 16b32dd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions invisible_cities/dataflow/dataflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,15 @@ def slice(*args, close_all=False):
if step is None: step = 1
if stop is None: stopper = it.count()
else : stopper = range((stop - start + step - 1) // step)

@coroutine
def slice_loop(target):
with closing(target):
for _ in range(start) : yield
if stop is not None and start >= stop : yield
for _ in range(start) : yield
for _ in stopper:
target.send((yield))
for _ in range(step - 1) : yield
for _ in range(step - 1) : yield
if close_all: raise StopPipeline
while True:
yield
Expand Down

0 comments on commit 16b32dd

Please sign in to comment.