[pypy-svn] r69608 - in pypy/branch/stringbuilder/pypy: interpreter objspace/std objspace/std/test

fijal at codespeak.net fijal at codespeak.net
Tue Nov 24 19:04:26 CET 2009


Author: fijal
Date: Tue Nov 24 19:04:26 2009
New Revision: 69608

Modified:
   pypy/branch/stringbuilder/pypy/interpreter/baseobjspace.py
   pypy/branch/stringbuilder/pypy/objspace/std/objspace.py
   pypy/branch/stringbuilder/pypy/objspace/std/test/test_iterobject.py
Log:
A test and a fix


Modified: pypy/branch/stringbuilder/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/stringbuilder/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/stringbuilder/pypy/interpreter/baseobjspace.py	Tue Nov 24 19:04:26 2009
@@ -671,7 +671,8 @@
     def fixedview(self, w_iterable, expected_lenght=-1):
         """ A fixed list view of w_iterable. Don't modify the result
         """
-        return make_sure_not_resized(self.unpackiterable(w_iterable)[:])
+        return make_sure_not_resized(self.unpackiterable(w_iterable,
+                                                         expected_lenght)[:])
 
     def listview(self, w_iterable):
         """ A non-fixed view of w_iterable. Don't modify the result

Modified: pypy/branch/stringbuilder/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/stringbuilder/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/stringbuilder/pypy/objspace/std/objspace.py	Tue Nov 24 19:04:26 2009
@@ -651,7 +651,7 @@
         elif isinstance(w_obj, W_ListObject):
             t = w_obj.wrappeditems[:]
         else:
-            return ObjSpace.fixedview(self, w_obj)
+            return ObjSpace.fixedview(self, w_obj, expected_length)
         if expected_length != -1 and len(t) != expected_length:
             raise UnpackValueError("Expected length %d, got %d" % (expected_length, len(t)))
         return t

Modified: pypy/branch/stringbuilder/pypy/objspace/std/test/test_iterobject.py
==============================================================================
--- pypy/branch/stringbuilder/pypy/objspace/std/test/test_iterobject.py	(original)
+++ pypy/branch/stringbuilder/pypy/objspace/std/test/test_iterobject.py	Tue Nov 24 19:04:26 2009
@@ -57,6 +57,31 @@
         raises(TypeError,
                           iter,
                           C())
+    
+    def test_unpacking_iter(self):
+        class BasicIterClass:
+            def __init__(self, n):
+                self.n = n
+                self.i = 0
+            def next(self):
+                res = self.i
+                if res >= self.n:
+                    raise StopIteration
+                self.i = res + 1
+                return res
+
+        class IteratingSequenceClass:
+            def __init__(self, n):
+                self.n = n
+            def __iter__(self):
+                return BasicIterClass(self.n)
+
+        try:
+            a, b = IteratingSequenceClass(3)
+        except ValueError:
+            pass
+        else:
+            raise Exception("did not raise")
 
 class AppTest_IterObject(object):
     def test_no_len_on_list_iter(self):



More information about the Pypy-commit mailing list