New submission from Serhiy Storchaka: 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) True >>> b''.startswith(b'', 1, 0) False Python 2: >>> ''.startswith('', 1, 0) False >>> u''.startswith(u'', 1, 0) True 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. ---------- components: Interpreter Core files: str_tailmatch.patch keywords: patch messages: 244027 nosy: serhiy.storchaka priority: normal severity: normal stage: patch review status: open title: Inconsistency in startswith/endswith type: behavior versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6 Added file: http://bugs.python.org/file39492/str_tailmatch.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24284> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com