[Python-bugs-list] [ python-Bugs-493951 ] string.{starts,ends}with vs slices
noreply@sourceforge.net
noreply@sourceforge.net
Sun, 16 Dec 2001 12:03:48 -0800
Bugs item #493951, was opened at 2001-12-16 11:23
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=493951&group_id=5470
Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: Remind
Priority: 5
Submitted By: Tim Peters (tim_one)
Assigned to: Barry Warsaw (bwarsaw)
Summary: string.{starts,ends}with vs slices
Initial Comment:
The attached test shows many cases where
string.startswith() and string.endswith() fail to
handle negative slice indices correctly. The failures
are in both the start and end indices. I stumbled
into this when tracking down why (what turned out to
be) this didn't work:
>>> file = 'difflib.pyc'
>>> file.endswith('.py', 0, -1) # should be 1
0
>>> file[0:-1].endswith('.py') # like this is
1
>>>
Can we risk changing this for 2.2? Don't know. If
not, reduce the priority.
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2001-12-16 12:03
Message:
Logged In: YES
user_id=31435
I can't guess what the docs intended to say (they're vague -
- I can read them several ways).
In all other cases where optional string-method args
named "start" and "end" are accepted (find(), rfind(), count
(), index(), rindex()), the docs are clear that they're
interpreted as slice notation. It doesn't make sense for
the two newest methods to behave differently in this
respect.
The unit tests aren't evidence one way or the other to me --
the behavior of negative indices should be covered by the
tests no matter what the intended semantics.
Overall, I expect the behavior here is an accident (as
opposed to intended).
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-16 11:45
Message:
Logged In: YES
user_id=6380
Hm, the docs don't exactly suggest that negative indices
would be supported. While that would be nice, it's
definitely a feature request, so no, please don't do this in
2.2. (The absent of unit tests for negative indices also
suggests this was not an oversight. :-)
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-12-16 11:24
Message:
Logged In: YES
user_id=31435
Attached the test case.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=493951&group_id=5470