[pypy-svn] pypy default: Fix an AssertionError with "buffer('x')[1:0]"

amauryfa commits-noreply at bitbucket.org
Mon Jan 17 13:54:30 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r40762:7d96196d9424
Date: 2011-01-17 13:51 +0100
http://bitbucket.org/pypy/pypy/changeset/7d96196d9424/

Log:	Fix an AssertionError with "buffer('x')[1:0]"

diff --git a/pypy/interpreter/buffer.py b/pypy/interpreter/buffer.py
--- a/pypy/interpreter/buffer.py
+++ b/pypy/interpreter/buffer.py
@@ -222,8 +222,10 @@
         return self.value[index]
 
     def getslice(self, start, stop, step, size):
+        if size == 0:
+            return ""
         if step == 1:
-            assert start >= 0 and stop >= 0
+            assert 0 <= start <= stop
             return self.value[start:stop]
         return "".join([self.value[start + i*step] for i in xrange(size)])
 

diff --git a/pypy/objspace/std/test/test_stringobject.py b/pypy/objspace/std/test/test_stringobject.py
--- a/pypy/objspace/std/test/test_stringobject.py
+++ b/pypy/objspace/std/test/test_stringobject.py
@@ -661,6 +661,7 @@
         assert len(b) == 5
         assert b[-1] == "o"
         assert b[:] == "hello"
+        assert b[1:0] == ""
         raises(TypeError, "b[3] = 'x'")
 
     def test_getnewargs(self):


More information about the Pypy-commit mailing list