[pypy-svn] pypy default: Support None for indexes.
alex_gaynor
commits-noreply at bitbucket.org
Thu Feb 3 05:55:55 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r41580:368285d0d54f
Date: 2011-02-02 23:55 -0500
http://bitbucket.org/pypy/pypy/changeset/368285d0d54f/
Log: Support None for indexes.
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
@@ -579,6 +579,9 @@
assert u[j+2] == u'3'
assert u'123' * i == i * u'123'
+ def test_index(self):
+ assert u"rrarrrrrrrrra".index(u'a', 4, None) == 12
+
def test_rindex(self):
from sys import maxint
assert u'abcdefghiabc'.rindex(u'') == 12
@@ -586,6 +589,8 @@
assert u'abcdefghiabc'.rindex(u'abc') == 9
assert u'abcdefghiabc'.rindex(u'abc', 0, -1) == 0
assert u'abcdefghiabc'.rindex(u'abc', -4*maxint, 4*maxint) == 9
+ assert u'rrarrrrrrrrra'.rindex(u'a', 4, None) == 12
+
raises(ValueError, u'abcdefghiabc'.rindex, u'hib')
raises(ValueError, u'defghiabc'.rindex, u'def', 1)
raises(ValueError, u'defghiabc'.rindex, u'abc', 0, -1)
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
@@ -476,6 +476,10 @@
assert isinstance(w_sub, W_UnicodeObject)
self = w_self._value
sub = w_sub._value
+
+ if space.is_w(w_end, space.w_None):
+ w_end = space.len(w_self)
+
if upper_bound:
start = slicetype.adapt_bound(space, len(self), w_start)
end = slicetype.adapt_bound(space, len(self), w_end)
More information about the Pypy-commit
mailing list