Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue24284

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:Inconsistency in startswith/endswith
Type:behaviorStage:resolved
Components:Interpreter CoreVersions:Python 3.6, Python 3.5
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: serhiy.storchakaNosy List: martin.panter, python-dev, r.david.murray, rhettinger, serhiy.storchaka
Priority:normalKeywords:patch

Created on2015-05-25 11:41 byserhiy.storchaka, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
str_tailmatch.patchserhiy.storchaka,2015-05-25 11:41review
Messages (8)
msg244027 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2015-05-25 11:41
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)FalsePython 2:>>> ''.startswith('', 1, 0)False>>> u''.startswith(u'', 1, 0)TrueIf 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. Seeissue24243 for more detailed discussion.Proposed patch fixes str.startswith and str.endswith.
msg244036 -(view)Author: R. David Murray (r.david.murray)*(Python committer)Date: 2015-05-25 14:02
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.
msg244068 -(view)Author: Martin Panter (martin.panter)*(Python committer)Date: 2015-05-26 00:19
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?
msg244106 -(view)Author: R. David Murray (r.david.murray)*(Python committer)Date: 2015-05-26 14:43
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.
msg244124 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2015-05-26 18:56
Could you please help me with wording?
msg244139 -(view)Author: Martin Panter (martin.panter)*(Python committer)Date: 2015-05-26 22:14
How about this for What’s New:* The :meth:`str.startswith` and :meth:`str.endswith` methods no longer return ``True`` when finding the empty string and the indexes are completely out of range. See :issue:`24284`.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*.
msg244520 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2015-05-31 06:09
Thank you Martin.
msg244521 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2015-05-31 06:17
New changeseta82498f424fe by Serhiy Storchaka in branch '3.5':Issue#24284: The startswith and endswith methods of the str class no longerhttps://hg.python.org/cpython/rev/a82498f424feNew changeset04162e06323f by Serhiy Storchaka in branch 'default':Issue#24284: The startswith and endswith methods of the str class no longerhttps://hg.python.org/cpython/rev/04162e06323f
History
DateUserActionArgs
2022-04-11 14:58:17adminsetgithub: 68472
2015-05-31 06:17:31serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-05-31 06:17:05python-devsetnosy: +python-dev
messages: +msg244521
2015-05-31 06:09:05serhiy.storchakasetassignee:serhiy.storchaka
messages: +msg244520
versions: + Python 3.6
2015-05-26 22:14:53martin.pantersetmessages: +msg244139
2015-05-26 18:56:46serhiy.storchakasetmessages: +msg244124
2015-05-26 14:43:20r.david.murraysetmessages: +msg244106
2015-05-26 00:19:28martin.pantersetnosy: +martin.panter
messages: +msg244068
2015-05-25 22:01:43rhettingersetnosy: +rhettinger
2015-05-25 14:02:32r.david.murraysetnosy: +r.david.murray

messages: +msg244036
versions: - Python 2.7, Python 3.4, Python 3.6
2015-05-25 11:41:27serhiy.storchakacreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp