This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients benjamin.peterson, docs@python, ezio.melotti, lemburg, martin.panter, pitrou, r.david.murray, serhiy.storchaka, swanson, vstinner
Date 2015-05-20.14:03:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1432130598.76.0.388031542143.issue24243@psf.upfronthosting.co.za>
In-reply-to
Content
Changing behavior of such base methods is dangerous and can break existing code. Even if the behavior is wrong, some code can depends on it. We should be very careful with this.

There are several simple invariants for these methods.

s1.index(s2, start, end) (for non-negative indices) returns minimal index i such that start <= i and i + len(s2) <= end and s1[i: i + len(s2)] = s2. Or raise an exception if such index doesn't exist. find() returns -1 instead of an exception. Therefore "".find("", 1, 0) should be -1 and it is. All right.

The only bug is in inconsistency in startswith/endswith between str and bytes (unicode and str in Python 2). The worse, the behavior of str in Python 2 and Python 3 is different.

s1.startswith(s2, start, end) (for non-negative indices and non-tuple s2) is equivalent to start + len(s2) <= end and s2[start: start + len(s2)] == s2. Or to s1.find(s2, start, end) == start. Therefore "".startswith("", 1, 0) should be False, and it is for bytes and str in Python 2. The behavior of "".startswith("", 1, 0) in Python 3 and u"".startswith(u"", 1, 0) in Python 3 is wrong.

The question is can we fix this behavior in default branch (I think rather yes) and should we fix it in maintained releases (doubt)?
History
Date User Action Args
2015-05-20 14:03:18serhiy.storchakasetrecipients: + serhiy.storchaka, lemburg, pitrou, vstinner, benjamin.peterson, ezio.melotti, r.david.murray, docs@python, martin.panter, swanson
2015-05-20 14:03:18serhiy.storchakasetmessageid: <1432130598.76.0.388031542143.issue24243@psf.upfronthosting.co.za>
2015-05-20 14:03:18serhiy.storchakalinkissue24243 messages
2015-05-20 14:03:18serhiy.storchakacreate