[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: You can use mo.group(1, 2). If you need to slice arbitrary groups, you can slice the result of the groups() method (which is just a tuple). The re module is already complex, and let use existing API rather than add the new one. -- resolution: -> re

[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-03 Thread Michael Selik
Michael Selik added the comment: Sorry, it looks like I got the issue number wrong. My comparison should not have been with #24454, but instead with an issue I can't locate at the moment. Reproducing the example: for g0, g1, g2 in re.finditer(r'(\d+)/(\d+)', 'Is 1/3 the same as 2/6?'):

[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-03 Thread Michael Selik
Michael Selik added the comment: Yesterday I wanted to do a destructuring bind on a slice of groups in a finditer. Similar situation to the use case of Issue #24454. It might not be "normal code" but I end up in that situation every month or so when parsing semi-structured documents. I found m

[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-03 Thread Eric V. Smith
Eric V. Smith added the comment: Short of a compelling use case, I suggest we reject this enhancement request. len() was deliberately not added in #24454. It's not like any normal code would be iterating over match groups. -- nosy: +eric.smith ___ P

[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This has already been discussed in other issues. Adding support of indexing opened a can of worms. len() for match objects is ambiguous because of the group 0. Implementing len() will make the match object iterable, but in a way incompatible with issue9529

[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-03 Thread Xiang Zhang
Xiang Zhang added the comment: See also #24454. -- nosy: +serhiy.storchaka, xiang.zhang ___ Python tracker ___ ___ Python-bugs-list ma

[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-02 Thread Michael Selik
Michael Selik added the comment: This would also enable negative indexing, which currently raises "IndexError: no such group". Edit: I meant whole numbers, not natural numbers. -- versions: +Python 3.7 ___ Python tracker

[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-02 Thread Michael Selik
Changes by Michael Selik : -- components: +Regular Expressions nosy: +ezio.melotti, mrabarnett type: -> enhancement ___ Python tracker ___ __

[issue29965] MatchObject __getitem__() should support slicing and len

2017-04-02 Thread Michael Selik
New submission from Michael Selik: Currently, slicing a MatchObject causes an IndexError and len() a TypeError. It's natural to expect slicing and len to work on objects of a finite length that index by natural numbers. -- messages: 291050 nosy: selik priority: normal severity: normal