[pypy-svn] rev 692 - in pypy/trunk/src/pypy/objspace/std: . test

mwh at codespeak.net mwh at codespeak.net
Thu May 29 17:05:07 CEST 2003


Author: mwh
Date: Thu May 29 17:05:06 2003
New Revision: 692

Added:
   pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py
Modified:
   pypy/trunk/src/pypy/objspace/std/listobject.py
   pypy/trunk/src/pypy/objspace/std/sliceobject.py
   pypy/trunk/src/pypy/objspace/std/stringobject.py
   pypy/trunk/src/pypy/objspace/std/tupleobject.py
Log:
Remove now-superfluous 'space' argument to W_SliceObject.indices and all
call sites.  Add one test for same.


Modified: pypy/trunk/src/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/listobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/listobject.py	Thu May 29 17:05:06 2003
@@ -78,7 +78,7 @@
 def getitem_list_slice(space, w_list, w_slice):
     items = w_list.ob_item
     w_length = space.wrap(w_list.ob_size)
-    w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length)
+    w_start, w_stop, w_step, w_slicelength = w_slice.indices(w_length)
     start       = space.unwrap(w_start)
     step        = space.unwrap(w_step)
     slicelength = space.unwrap(w_slicelength)
@@ -173,7 +173,7 @@
 def setitem_list_slice(space, w_list, w_slice, w_list2):
     items = w_list.ob_item
     w_length = space.wrap(w_list.ob_size)
-    w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length)
+    w_start, w_stop, w_step, w_slicelength = w_slice.indices(w_length)
     start       = space.unwrap(w_start)
     step        = space.unwrap(w_step)
     slicelength = space.unwrap(w_slicelength)

Modified: pypy/trunk/src/pypy/objspace/std/sliceobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/sliceobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/sliceobject.py	Thu May 29 17:05:06 2003
@@ -12,14 +12,12 @@
         w_self.w_start = w_start
         w_self.w_stop = w_stop
         w_self.w_step = w_step
-    def indices(w_self, space, w_length):
-        w_ret = space.gethelper(appfile).call("sliceindices", [w_self, w_length])
-        w_start, w_stop, w_step, w_slicelength = space.unpackiterable(w_ret, 4)
-        return w_start, w_stop, w_step, w_slicelength
-    def indices2(w_self, w_length):
+    def indices(w_self, w_length):
         w_ret = w_self.space.gethelper(appfile).call("sliceindices", [w_self, w_length])
         w_start, w_stop, w_step, w_slicelength = w_self.space.unpackiterable(w_ret, 4)
-        return w_self.space.newtuple([w_start, w_stop, w_step, w_slicelength])
+        return w_start, w_stop, w_step, w_slicelength
+    def indices2(w_self, w_length):
+        return w_self.space.newtuple(w_self.indices(w_length)[:-1])
 
 
 def getattr_slice_any(space, w_slice, w_attr):

Modified: pypy/trunk/src/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/stringobject.py	Thu May 29 17:05:06 2003
@@ -231,7 +231,7 @@
 def getitem_str_slice(space, w_str, w_slice):
     w = space.wrap
     u = space.unwrap
-    w_start, w_stop, w_step, w_sl = w_slice.indices(space, w(w_str._value.len))
+    w_start, w_stop, w_step, w_sl = w_slice.indices(w(w_str._value.len))
     start = u(w_start)
     stop = u(w_stop)
     step = u(w_step)

Added: pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/objspace/std/test/test_sliceobject.py	Thu May 29 17:05:06 2003
@@ -0,0 +1,24 @@
+import testsupport
+
+class TestW_SliceObject(testsupport.TestCase):
+
+    def setUp(self):
+        self.space = testsupport.objspace()
+
+    def tearDown(self):
+        pass
+
+    def equal_indices(self, got, expected):
+        for g, e in zip(got, expected):
+            self.assertEqual_w(g, self.space.wrap(e))
+
+    def test_indices(self):
+        space = self.space
+        w = space.wrap
+        w_None = space.w_None
+        w_slice = space.newslice(w_None, w_None, w_None)
+        self.equal_indices(w_slice.indices(w(6)), (0, 6, 1, 6))
+        
+
+if __name__ == '__main__':
+    testsupport.main()

Modified: pypy/trunk/src/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/tupleobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/tupleobject.py	Thu May 29 17:05:06 2003
@@ -46,7 +46,7 @@
 def getitem_tuple_slice(space, w_tuple, w_slice):
     items = w_tuple.wrappeditems
     w_length = space.wrap(len(items))
-    w_start, w_stop, w_step, w_slicelength = w_slice.indices(space, w_length)
+    w_start, w_stop, w_step, w_slicelength = w_slice.indices(w_length)
     start       = space.unwrap(w_start)
     step        = space.unwrap(w_step)
     slicelength = space.unwrap(w_slicelength)


More information about the Pypy-commit mailing list