[issue7940] re.finditer and re.findall should support negative end positions

2019-09-09 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

Note that changing the current behavior is a breaking change. For example 
someone can use `pattern.findall(text, curpos-50, curpos+50)` to search in the 
range ±50 characters from the current position. If negative positions change 
meaning, this will break a code for curpos < 50.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2019-09-09 Thread Zachary Ware


Zachary Ware  added the comment:

Ezio requested further opinions, so here's mine.  I don't think the current 
behavior makes sense; I doubt anyone actually expects a negative index to be 
squashed to 0, especially for endpos.  I'm not certain that allowing negative 
indexes is really necessary, but seems nicer than raising an exception which 
would be the other acceptable option to me.

--
nosy: +zach.ware

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2019-07-15 Thread Ezio Melotti


Ezio Melotti  added the comment:

> Are there any real world examples which show the benefit of supporting 
> negative indices?

A common case is ignoring parentheses at the beginning/end, e.g.
>>> re.compile('[^,]+').findall('(foo,123,(),bar)')
['(foo', '123', '()', 'bar)']
>>> # ignore the surrounding ()
>>> re.compile('[^,]+').findall('(foo,123,(),bar)', 1, 15)
['foo', '123', '()', 'bar']
>>>
>>> # extract attributes from a tag (poc, doesn't handle all cases)
>>> re.compile('[^ ]+').findall('', 7, 
>>> 39)
['type="checkbox"', 'id="foo"', 'checked']

In both cases using -1 as endpos is simpler.

--
versions: +Python 3.9 -Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2019-07-15 Thread M. Anil Tuncel


M. Anil Tuncel  added the comment:

I guess the use of negative indices serve the same purpose here as in lists or 
strings. 
Though as Ezio pointed out, the current behaviour is already accepting negative 
indices but providing inconsistent results in comparison to various other 
Python modules that support negative indices.

In my opinion:
If the negative indices are to be used here (which is what the current 
implementation suggests), they should behave in the same way as the rest of the 
Python modules. 
Otherwise, perhaps negative indices should not be allowed here at all. 

What do you think?

P.S. this patch is already applied to the regex module by @mrabarnett

--
nosy: +anilbey

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2019-07-14 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Are there any real world examples which show the benefit of supporting negative 
indices?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2019-07-14 Thread Ezio Melotti


Ezio Melotti  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2019-07-14 Thread Ezio Melotti


Ezio Melotti  added the comment:

The current behavior is inconsistent because the start position accepts both 
positive and negative indices, whereas the end position only accepts positive 
indices.
I think the proposal and the PR written by Anil are reasonable and should be 
merged.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2019-07-13 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

-1 on the proposal.  We don't know of any strong use cases, so there isn't a 
real problem being solved here.  Rather than providing a benefit, this feature 
request makes it more likely that people will write convoluted code or that it 
will let bugs pass silently that would otherwise be caught.

ISTM the actual issue here is an incorrect user expectation that "all things 
that having indexing will support negative indexing".  While it is common for 
objects to implement negative index support, it is not universal or required.  
Even collections.abc.Sequence does not insist on negative index support.

I think this warrants a FAQ entry (which should also mention that slice support 
as well is not universal or required, some objects have it, some don't).

Reclassifying this as documentation issue.

--
assignee:  -> docs@python
components: +Documentation -Library (Lib), Regular Expressions
nosy: +docs@python, rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2019-07-13 Thread Roundup Robot


Change by Roundup Robot :


--
pull_requests: +14540
pull_request: https://github.com/python/cpython/pull/14744

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2014-10-23 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
components: +Regular Expressions
priority: normal - low
stage: needs patch - patch review
versions: +Python 3.5 -Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7940
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2014-02-03 Thread Mark Lawrence

Changes by Mark Lawrence breamore...@yahoo.co.uk:


--
nosy:  -BreamoreBoy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7940
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2013-05-26 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I'm worrying about backward compatibility. See also issue7951.

--
nosy: +serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7940
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2013-05-26 Thread Matthew Barnett

Matthew Barnett added the comment:

Like the OP, I would've expected it to handle negative indexes the way that 
strings do.

In practice, I wouldn't normally provide negative indexes; I'd use some string 
or regex method to determine the search limits, and then pass them to finditer 
and findall, so they'd be non-negative anyway.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7940
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2013-05-25 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
components: +Library (Lib)
stage: test needed - needs patch
versions: +Python 3.4 -Python 2.7, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7940
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2013-05-25 Thread Matthew Barnett

Matthew Barnett added the comment:

I've attached a patch.

--
keywords: +patch
Added file: http://bugs.python.org/file30377/issue7940.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7940
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2013-05-23 Thread Mark Lawrence

Mark Lawrence added the comment:

Has this been fixed in the regex module?

--
nosy: +BreamoreBoy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7940
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7940] re.finditer and re.findall should support negative end positions

2013-05-23 Thread Matthew Barnett

Matthew Barnett added the comment:

Yes. As msg99456 suggests, I fixed it the my source code before posting.

Compare re in Python 3.3.2:

 re.compile('x').findall('', 1, 3)
['x', 'x']
 re.compile('x').findall('', 1, -1)
[]

with regex:

 regex.compile('x').findall('', 1, 3)
['x', 'x']
 regex.compile('x').findall('', 1, -1)
['x', 'x']

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7940
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com