[pypy-svn] r51385 - in pypy/dist/pypy/objspace/std: . test

fijal at codespeak.net fijal at codespeak.net
Mon Feb 11 15:46:51 CET 2008


Author: fijal
Date: Mon Feb 11 15:46:49 2008
New Revision: 51385

Modified:
   pypy/dist/pypy/objspace/std/objspace.py
   pypy/dist/pypy/objspace/std/test/test_stdobjspace.py
Log:
sliceindices shall return unpacked tuple. the test and fix for the fallback
version.


Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py	(original)
+++ pypy/dist/pypy/objspace/std/objspace.py	Mon Feb 11 15:46:49 2008
@@ -601,9 +601,14 @@
     def sliceindices(self, w_slice, w_length):
         if isinstance(w_slice, W_SliceObject):
             a, b, c = w_slice.indices3(self, self.int_w(w_length))
-            return self.newtuple([a, b, c])
+            return (a, b, c)
         w_indices = self.getattr(w_slice, self.wrap('indices'))
-        return self.call_function(w_indices, w_length)
+        w_tup = self.call_function(w_indices, w_length)
+        l_w = self.unpackiterable(w_tup)
+        if not len(l_w) == 3:
+            raise OperationError(self.w_ValueError,
+                                 self.wrap("Expected tuple of length 3"))
+        return self.int_w(l_w[0]), self.int_w(l_w[1]), self.int_w(l_w[2])
 
     def is_(self, w_one, w_two):
         # XXX a bit of hacking to gain more speed 

Modified: pypy/dist/pypy/objspace/std/test/test_stdobjspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_stdobjspace.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_stdobjspace.py	Mon Feb 11 15:46:49 2008
@@ -1,4 +1,5 @@
 from pypy.interpreter.error import OperationError
+from pypy.interpreter.gateway import app2interp
 
 class TestW_StdObjSpace:
 
@@ -34,8 +35,14 @@
 
     def test_sliceindices(self):
         space = self.space
+        w_obj = space.appexec([], """():
+            class Stuff(object):
+                def indices(self, l):
+                    return 1,2,3
+            return Stuff()
+        """)
         w = space.wrap
         w_slice = space.newslice(w(1), w(2), w(1))
-        assert space.unpacktuple(space.sliceindices(w_slice, w(3))) == [1,2,1]
-        
+        assert space.sliceindices(w_slice, w(3)) == (1,2,1)
+        assert space.sliceindices(w_obj, w(3)) == (1,2,3)
 



More information about the Pypy-commit mailing list