[pypy-svn] r75367 - in pypy/branch/multijit-4/pypy/module/__builtin__: . test

arigo at codespeak.net arigo at codespeak.net
Sun Jun 13 11:36:50 CEST 2010


Author: arigo
Date: Sun Jun 13 11:36:48 2010
New Revision: 75367

Modified:
   pypy/branch/multijit-4/pypy/module/__builtin__/functional.py
   pypy/branch/multijit-4/pypy/module/__builtin__/test/test_functional.py
Log:
Merge r75331 and r75332 from trunk.


Modified: pypy/branch/multijit-4/pypy/module/__builtin__/functional.py
==============================================================================
--- pypy/branch/multijit-4/pypy/module/__builtin__/functional.py	(original)
+++ pypy/branch/multijit-4/pypy/module/__builtin__/functional.py	Sun Jun 13 11:36:48 2010
@@ -187,13 +187,15 @@
         cont = False
         args_w = [space.w_None] * num_iterators
         for i in range(num_iterators):
-            try:
-                args_w[i] = space.next(iterators_w[i])
-            except OperationError, e:
-                if not e.match(space, space.w_StopIteration):
-                    raise
-            else:
-                cont = True
+            if iterators_w[i] is not None:
+                try:
+                    args_w[i] = space.next(iterators_w[i])
+                except OperationError, e:
+                    if not e.match(space, space.w_StopIteration):
+                        raise
+                    iterators_w[i] = None
+                else:
+                    cont = True
         if cont:
             w_args = space.newtuple(args_w)
             if none_func:

Modified: pypy/branch/multijit-4/pypy/module/__builtin__/test/test_functional.py
==============================================================================
--- pypy/branch/multijit-4/pypy/module/__builtin__/test/test_functional.py	(original)
+++ pypy/branch/multijit-4/pypy/module/__builtin__/test/test_functional.py	Sun Jun 13 11:36:48 2010
@@ -58,6 +58,25 @@
       b = []
       assert map(lambda x, y: x, a, b) == a
 
+   def test_map_iterables(self):
+      class A(object):
+         def __init__(self, n):
+            self.n = n
+         def __iter__(self):
+            return B(self.n)
+      class B(object):
+         def __init__(self, n):
+            self.n = n
+         def next(self):
+            self.n -= 1
+            if self.n == 0: raise StopIteration
+            return self.n
+      result = map(None, A(3), A(8))
+      # this also checks that B.next() is not called any more after it
+      # raised StopIteration once
+      assert result == [(2, 7), (1, 6), (None, 5), (None, 4),
+                        (None, 3), (None, 2), (None, 1)]
+
 class AppTestZip:
    def test_one_list(self):
       assert zip([1,2,3]) == [(1,), (2,), (3,)]



More information about the Pypy-commit mailing list