[pypy-svn] r60073 - in pypy/trunk/pypy/objspace: . std/test

fijal at codespeak.net fijal at codespeak.net
Sat Nov 22 15:49:09 CET 2008


Author: fijal
Date: Sat Nov 22 15:49:09 2008
New Revision: 60073

Modified:
   pypy/trunk/pypy/objspace/descroperation.py
   pypy/trunk/pypy/objspace/std/test/test_index.py
Log:
getslice works with negative parameters and without length. For now
we don't differentiate __len__ raising TypeError and non-existant one.


Modified: pypy/trunk/pypy/objspace/descroperation.py
==============================================================================
--- pypy/trunk/pypy/objspace/descroperation.py	(original)
+++ pypy/trunk/pypy/objspace/descroperation.py	Sat Nov 22 15:49:09 2008
@@ -494,10 +494,17 @@
     else:
         w_start = space.wrap(space.getindex_w(w_start, None))
         if space.is_true(space.lt(w_start, space.wrap(0))):
-            w_start = space.add(w_start, space.len(w_obj))
+            try:
+                w_start = space.add(w_start, space.len(w_obj))
+            except OperationError, e:
+                if not ((e.match(space, space.w_AttributeError) or
+                         e.match(space, space.w_TypeError))):
+                    raise
             # NB. the language ref is inconsistent with the new-style class
             # behavior when w_obj doesn't implement __len__(), so we just
-            # ignore this case.
+            # follow cpython. Also note that CPython slots make it easier
+            # to check for object implementing it or not. We just catch errors
+            # so this behavior is slightly different
     if space.is_w(w_stop, space.w_None):
         w_stop = space.wrap(slice_max)
     else:

Modified: pypy/trunk/pypy/objspace/std/test/test_index.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_index.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_index.py	Sat Nov 22 15:49:09 2008
@@ -305,6 +305,13 @@
         assert x[self.neg:self.pos] == (-1, maxint)
         assert x[self.neg:self.pos:1].indices(maxint) == (0, maxint, 1)
 
+    def test_getslice_nolength(self):
+        class X(object):
+            def __getslice__(self, i, j):
+                return (i, j)
+
+        assert X()[-2:1] == (-2, 1)
+
     def test_getitem_classic(self):
         from sys import maxint
         class Empty: pass



More information about the Pypy-commit mailing list