[pypy-svn] pypy default: Allow None for start index in unicode.index

alex_gaynor commits-noreply at bitbucket.org
Fri Feb 4 05:26:49 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r41599:f4961caf91a7
Date: 2011-02-03 23:26 -0500
http://bitbucket.org/pypy/pypy/changeset/f4961caf91a7/

Log:	Allow None for start index in unicode.index

diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -581,6 +581,7 @@
 
     def test_index(self):
         assert u"rrarrrrrrrrra".index(u'a', 4, None) == 12
+        assert u"rrarrrrrrrrra".index(u'a', None, 6) == 2
 
     def test_rindex(self):
         from sys import maxint

diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -477,6 +477,8 @@
     self = w_self._value
     sub = w_sub._value
 
+    if space.is_w(w_start, space.w_None):
+        w_start = space.wrap(0)
     if space.is_w(w_end, space.w_None):
         w_end = space.len(w_self)
 

diff --git a/pypy/objspace/std/ropeunicodeobject.py b/pypy/objspace/std/ropeunicodeobject.py
--- a/pypy/objspace/std/ropeunicodeobject.py
+++ b/pypy/objspace/std/ropeunicodeobject.py
@@ -482,6 +482,8 @@
 def _convert_idx_params(space, w_self, w_start, w_end):
     self = w_self._node
     length = w_self._node.length()
+    if space.is_w(w_start, space.w_None):
+        w_start = space.wrap(0)
     if space.is_w(w_end, space.w_None):
         w_end = space.len(w_self)
     start = slicetype.adapt_bound(space, length, w_start)


More information about the Pypy-commit mailing list