Author: Matti Picus <[email protected]>
Branch: unicode-utf8-py3
Changeset: r95701:d7b0f65f80a2
Date: 2019-01-23 16:28 +0200
http://bitbucket.org/pypy/pypy/changeset/d7b0f65f80a2/
Log: match startswith, endswith cpython behaviour for
needle='',start>0,end==0
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
@@ -156,7 +156,8 @@
assert w_res is space.newbool(expected)
expected = u.startswith(v, start, start + len1)
- if expected and start > len(u):
+ if ((expected and start > len(u)) or
+ (start > 0 and start + len1 ==0)):
expected = False # python2 vs. python3
w_res = space.call_method(w_u, 'startswith', w_v,
space.newint(start),
@@ -171,7 +172,8 @@
assert w_res is space.newbool(expected)
expected = u.endswith(v, start, start + len1)
- if expected and start > len(u):
+ if ((expected and start > len(u)) or
+ (start > 0 and start + len1 ==0)):
expected = False # python2 vs. python3
w_res = space.call_method(w_u, 'endswith', w_v,
space.newint(start),
@@ -626,6 +628,8 @@
assert ''.endswith('a') is False
assert 'x'.endswith('xx') is False
assert 'y'.endswith('xx') is False
+ assert 'x'.endswith('', 1, 0) is False
+
def test_endswith_more(self):
assert 'abc'.endswith('ab', 0, 2) is True
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
@@ -636,6 +636,8 @@
def descr_startswith(self, space, w_prefix, w_start=None, w_end=None):
start, end = self._unwrap_and_compute_idx_params(space, w_start, w_end)
value = self._utf8
+ if start > 0 and not space.is_none(w_end) and space.int_w(w_end) == 0:
+ return space.w_False
if space.isinstance_w(w_prefix, space.w_tuple):
return self._startswith_tuple(space, value, w_prefix, start, end)
try:
@@ -657,6 +659,9 @@
def descr_endswith(self, space, w_suffix, w_start=None, w_end=None):
start, end = self._unwrap_and_compute_idx_params(space, w_start, w_end)
value = self._utf8
+ # match cpython behaviour
+ if start > 0 and not space.is_none(w_end) and space.int_w(w_end) == 0:
+ return space.w_False
if space.isinstance_w(w_suffix, space.w_tuple):
return self._endswith_tuple(space, value, w_suffix, start, end)
try:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit