[pypy-svn] r80022 - in pypy/branch/fast-forward/pypy/module/itertools: . test

afa at codespeak.net afa at codespeak.net
Mon Dec 13 08:51:28 CET 2010


Author: afa
Date: Mon Dec 13 08:51:26 2010
New Revision: 80022

Modified:
   pypy/branch/fast-forward/pypy/module/itertools/interp_itertools.py
   pypy/branch/fast-forward/pypy/module/itertools/test/test_itertools.py
Log:
Fix an infinite loop with itertools.product(x, repeat=0)


Modified: pypy/branch/fast-forward/pypy/module/itertools/interp_itertools.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/itertools/interp_itertools.py	(original)
+++ pypy/branch/fast-forward/pypy/module/itertools/interp_itertools.py	Mon Dec 13 08:51:26 2010
@@ -1016,6 +1016,10 @@
         self.cont = True
 
     def roll_gears(self):
+        if self.num_gears == 0:
+            self.cont = False
+            return
+
         # Starting from the end of the gear indicies work to the front
         # incrementing the gear until the limit is reached. When the limit
         # is reached carry operation to the next gear

Modified: pypy/branch/fast-forward/pypy/module/itertools/test/test_itertools.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/itertools/test/test_itertools.py	(original)
+++ pypy/branch/fast-forward/pypy/module/itertools/test/test_itertools.py	Mon Dec 13 08:51:26 2010
@@ -752,3 +752,9 @@
         l = [1, 2]
         m = ['a']
         raises(TypeError, product, l, m, repeat=1, foo=2)
+
+    def test_product_empty(self):
+        from itertools import product
+        prod = product('abc', repeat=0)
+        assert prod.next() == ()
+        raises (StopIteration, prod.next)



More information about the Pypy-commit mailing list