-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistency in startswith/endswith #68472
Comments
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 The same issue exists for endswith. See bpo-24243 for more detailed discussion. Proposed patch fixes str.startswith and str.endswith. |
I think this can only be applied in a feature release (and I think it should be, because of the backward-compatibility-with-python2 issue). However, since this is potentially controversial, we need some more opinions. |
I can’t imagine much code would rely on either old or new behaviour. If you only put it into a feature release, would you have to document it as a change in behaviour? |
Just in the what's new porting section, I think. The fact that there "should" be very little to no code that relies on this is why I'd like to see it fixed. The fact that the report was a theoretical one, and not one that broke code, is why I think we should fix it only in 3.5. |
Could you please help me with wording? |
How about this for What’s New:
Perhaps that is good enough, but if you wanted to be more precise, I think the actual condition is if the *start* index is beyond the end of the string, or *end* is before *start*. |
Thank you Martin. |
New changeset a82498f424fe by Serhiy Storchaka in branch '3.5': New changeset 04162e06323f by Serhiy Storchaka in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: