Author ezio.melotti
Recipients docs@python, ezio.melotti, mrabarnett, rhettinger, serhiy.storchaka, timehorse, tlynn
Date 2019-07-14.14:01:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1563112918.31.0.236227535878.issue7940@roundup.psfhosted.org>
In-reply-to
Content
Sorry, I was wrong.  re.findall accepts negative indices for both start and end but they silently get converted to 0, which is arguably an unexpected behavior.

This is an example of the current behavior:
>>> s, e = 1, 4; re.compile('.').findall('abcde', s, e), 'abcde'[s:e]
(['b', 'c', 'd'], 'bcd')
>>> s, e = -4, 4; re.compile('.').findall('abcde', s, e), 'abcde'[s:e]
(['a', 'b', 'c', 'd'], 'bcd')
>>> s, e = 1, -1; re.compile('.').findall('abcde', s, e), 'abcde'[s:e]
([], 'bcd')
>>> s, e = -4, -1; re.compile('.').findall('abcde', s, e), 'abcde'[s:e]
([], 'bcd')

With the patch, all these return ['b', 'c', 'd'].  This change might indeed cause issues because it's a change in behavior, but I'm also not sure there are many cases where one would want a negative index to be treated as 0.  Maybe we could raise a FutureWarning in the next release and change the behavior afterwards?
History
Date User Action Args
2019-07-14 14:01:58ezio.melottisetrecipients: + ezio.melotti, rhettinger, tlynn, timehorse, mrabarnett, docs@python, serhiy.storchaka
2019-07-14 14:01:58ezio.melottisetmessageid: <1563112918.31.0.236227535878.issue7940@roundup.psfhosted.org>
2019-07-14 14:01:58ezio.melottilinkissue7940 messages
2019-07-14 14:01:58ezio.melotticreate