Skip to content

Commit 80f505d

Browse files
committed
[GH-33] Fix and add test for itertools.zip_longest.
PullRequest: graalpython/355
2 parents 222bafa + 40b8f5e commit 80f505d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_iterator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,10 @@ def test_iterator_in():
122122
assert 1 in (i for i in range(2))
123123
assert 1 in iter(range(2))
124124
assert 1 not in iter(range(1))
125+
126+
127+
def test_itertools_zip_longest():
128+
from itertools import zip_longest
129+
x = [1,2,3]
130+
y = [4,5,6,7]
131+
assert list(zip_longest(x,y)) == [(1, 4), (2, 5), (3, 6), (None, 7)], list(zip_longest(x,y))

graalpython/lib-graalpython/itertools.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,14 @@ def __next__(self):
637637
nb = len(self.iterators)
638638
if nb == 0:
639639
raise StopIteration
640-
return tuple(self._fetch(index) for index in range(nb))
640+
result = []
641+
for index in range(nb):
642+
result.append(self._fetch(index))
643+
return tuple(result)
641644

642645
def __new__(subtype, iter1, *args, fillvalue=None):
643646
self = object.__new__(subtype)
644647
self.fillvalue = fillvalue
645648
self.active = len(args) + 1
646-
self.iterators = [iter1] + args
649+
self.iterators = [iter(iter1)] + [iter(arg) for arg in args]
647650
return self

0 commit comments

Comments
 (0)