From: <pj...@us...> - 2008-11-14 00:02:21
|
Revision: 5576 http://jython.svn.sourceforge.net/jython/?rev=5576&view=rev Author: pjenvey Date: 2008-11-14 00:02:12 +0000 (Fri, 14 Nov 2008) Log Message: ----------- fix itertools.chain stopping short with two empty iters in a row Modified Paths: -------------- trunk/jython/Lib/test/test_iter_jy.py trunk/jython/src/org/python/modules/itertools.java Modified: trunk/jython/Lib/test/test_iter_jy.py =================================================================== --- trunk/jython/Lib/test/test_iter_jy.py 2008-11-12 19:33:58 UTC (rev 5575) +++ trunk/jython/Lib/test/test_iter_jy.py 2008-11-14 00:02:12 UTC (rev 5576) @@ -2,6 +2,7 @@ Made for Jython. """ +import itertools from test import test_support import unittest @@ -23,7 +24,10 @@ return str(index) + '!' self.assertEqual(iter(MyStr('ab')).next(), '0!') + def test_chain(self): + self.assertEqual(list(itertools.chain([], [], ['foo'])), ['foo']) + def test_main(): test_support.run_unittest(IterTestCase) Modified: trunk/jython/src/org/python/modules/itertools.java =================================================================== --- trunk/jython/src/org/python/modules/itertools.java 2008-11-12 19:33:58 UTC (rev 5575) +++ trunk/jython/src/org/python/modules/itertools.java 2008-11-14 00:02:12 UTC (rev 5576) @@ -161,20 +161,14 @@ int iteratorIndex = 0; public PyObject __iternext__() { - if (iteratorIndex >= iterators.length) { - return null; - } - PyObject obj = nextElement(iterators[iteratorIndex]); - - if (obj == null) { - // increase the iteratorIndex and see if we have more - // iterators to work with - iteratorIndex++; - if (iteratorIndex < iterators.length) { - obj = nextElement(iterators[iteratorIndex]); + PyObject next = null; + for (; iteratorIndex < iterators.length; iteratorIndex++) { + next = nextElement(iterators[iteratorIndex]); + if (next != null) { + break; } } - return obj; + return next; } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |