Skip to content

Commit 5846016

Browse files
committed
[jobs] Catch StopIteration for Python 3.7 compatibility
Since Python 3.7 was introduced, StopIteration exceptions are raised directly when 'next()' doesn't generate a new item. This patch adds compatibility other Python versions catching this exception. Signed-off-by: Santiago Dueñas <sduenas@bitergia.com>
1 parent ea949a0 commit 5846016

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

sortinghat/core/jobs.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,10 @@ def _iter_split(iterator, size=None):
468468
# This code is based on Ashley Waite's answer to StackOverflow question
469469
# "split a generator/iterable every n items in python (splitEvery)"
470470
# (https://stackoverflow.com/a/44320132).
471-
while True:
472-
slice_iter = itertools.islice(iterator, size)
473-
peek = next(slice_iter)
474-
yield itertools.chain([peek], slice_iter)
471+
try:
472+
while True:
473+
slice_iter = itertools.islice(iterator, size)
474+
peek = next(slice_iter)
475+
yield itertools.chain([peek], slice_iter)
476+
except StopIteration:
477+
return

0 commit comments

Comments
 (0)