[pypy-svn] r75331 - in pypy/trunk/pypy/module/__builtin__: . test

arigo at codespeak.net arigo at codespeak.net
Sat Jun 12 17:38:40 CEST 2010


Author: arigo
Date: Sat Jun 12 17:38:34 2010
New Revision: 75331

Modified:
   pypy/trunk/pypy/module/__builtin__/functional.py
   pypy/trunk/pypy/module/__builtin__/test/test_functional.py
Log:
Test and fix.


Modified: pypy/trunk/pypy/module/__builtin__/functional.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/functional.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/functional.py	Sat Jun 12 17:38:34 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/trunk/pypy/module/__builtin__/test/test_functional.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/test/test_functional.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/test/test_functional.py	Sat Jun 12 17:38:34 2010
@@ -58,6 +58,23 @@
       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))
+      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