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 serhiy.storchaka
Date 2015-05-25.11:41:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The behavior of startswith in corner case is inconsistent between str and bytes in Python 3, str and unicode in Python 2, and between str in Python 2 and Python 3.

Python 3:
>>> ''.startswith('', 1, 0)
>>> b''.startswith(b'', 1, 0)

Python 2:
>>> ''.startswith('', 1, 0)
>>> u''.startswith(u'', 1, 0)

If define s1.startswith(s2, start, end) for non-negative indices and non-tuple s2 as an equivalent to the expression `start + len(s2) <= end and s2[start: start + len(s2)] == s2` or to `s1.find(s2, start, end) == start`, "".startswith("", 1, 0) should be False.

The same issue exists for endswith. See issue24243 for more detailed discussion.

Proposed patch fixes str.startswith and str.endswith.
Date User Action Args
2015-05-25 11:41:27serhiy.storchakasetrecipients: + serhiy.storchaka
2015-05-25 11:41:27serhiy.storchakasetmessageid: <>
2015-05-25 11:41:27serhiy.storchakalinkissue24284 messages
2015-05-25 11:41:27serhiy.storchakacreate