[pypy-svn] r55075 - in pypy/dist/pypy/lib: . test2
antocuni at codespeak.net
antocuni at codespeak.net
Wed May 21 17:50:08 CEST 2008
Author: antocuni
Date: Wed May 21 17:50:07 2008
New Revision: 55075
Added:
pypy/dist/pypy/lib/test2/test_itertools.py (contents, props changed)
Modified:
pypy/dist/pypy/lib/itertools.py
Log:
the logic behind chain.next() was completely broken; add a failing
test, and fix it.
Modified: pypy/dist/pypy/lib/itertools.py
==============================================================================
--- pypy/dist/pypy/lib/itertools.py (original)
+++ pypy/dist/pypy/lib/itertools.py Wed May 21 17:50:07 2008
@@ -47,24 +47,15 @@
return self
def next(self):
- try:
- next_elt = self._cur_iterable_iter.next()
- except StopIteration:
- # The current list's iterator is exhausted, switch to next one
- self._cur_iterable_iter = iter(self._iterables_iter.next())
+ while True:
try:
- next_elt = self._cur_iterable_iter.next()
+ return self._cur_iterable_iter.next()
+ except StopIteration:
+ self._cur_iterable_iter = self._iterables_iter.next()
except AttributeError:
# CPython raises a TypeError when next() is not defined
raise TypeError('%s has no next() method' % \
(self._cur_iterable_iter))
- except AttributeError:
- # CPython raises a TypeError when next() is not defined
- raise TypeError('%s has no next() method' % \
- (self._cur_iterable_iter))
-
- return next_elt
-
class count:
"""Make an iterator that returns consecutive integers starting
Added: pypy/dist/pypy/lib/test2/test_itertools.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/test2/test_itertools.py Wed May 21 17:50:07 2008
@@ -0,0 +1,11 @@
+from pypy.conftest import gettestobjspace
+
+class AppTestItertools:
+ def setup_class(cls):
+ cls.space = gettestobjspace()
+ cls.w_itertools = cls.space.appexec([], "(): import itertools; return itertools")
+
+ def test_chain():
+ it = itertools.chain([], [1, 2, 3])
+ lst = list(it)
+ assert lst == [1, 2, 3]
More information about the Pypy-commit
mailing list