Ezio Melotti <ezio.melo...@gmail.com> added the comment:

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?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue7940>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to