[issue24454] Improve the usability of the match object named group API

2016-10-06 Thread irdb
Changes by irdb : -- nosy: +irdb ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailma

[issue24454] Improve the usability of the match object named group API

2016-09-11 Thread Roundup Robot
Roundup Robot added the comment: New changeset 9eb38e0f1cad by Eric V. Smith in branch 'default': Issue 24454: Removed unused match_getitem_doc. https://hg.python.org/cpython/rev/9eb38e0f1cad -- ___ Python tracker

[issue24454] Improve the usability of the match object named group API

2016-09-11 Thread Eric V. Smith
Eric V. Smith added the comment: On 9/11/2016 10:05 AM, Serhiy Storchaka wrote: > > Serhiy Storchaka added the comment: > > ./Modules/_sre.c:2425:14: warning: ‘match_getitem_doc’ defined but not used [- > Wunused-variable] Not in Visual Studio! Standby. --

[issue24454] Improve the usability of the match object named group API

2016-09-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: ./Modules/_sre.c:2425:14: warning: ‘match_getitem_doc’ defined but not used [- Wunused-variable] -- ___ Python tracker ___ ___

[issue24454] Improve the usability of the match object named group API

2016-09-11 Thread Eric V. Smith
Eric V. Smith added the comment: Fixed. Thanks, Serhiy. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http

[issue24454] Improve the usability of the match object named group API

2016-09-11 Thread Roundup Robot
Roundup Robot added the comment: New changeset 3265247e08f0 by Eric V. Smith in branch 'default': Issue 24454: Added whatsnew entry, removed __getitem__ from match_methods. Thanks Serhiy Storchaka. https://hg.python.org/cpython/rev/3265247e08f0 -- __

[issue24454] Improve the usability of the match object named group API

2016-09-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I meant Doc/whatsnew/3.6.rst. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscr

[issue24454] Improve the usability of the match object named group API

2016-09-11 Thread Eric V. Smith
Eric V. Smith added the comment: I added a note in Misc/NEWS. Is that not what you mean? I'll look at match_methods. -- ___ Python tracker ___ __

[issue24454] Improve the usability of the match object named group API

2016-09-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Please document this feature in What's News Eric. There is no need to add the __getitem__ method explicitly the the list of methods match_methods. It would be added automatically. -- ___ Python tracker

[issue24454] Improve the usability of the match object named group API

2016-09-11 Thread Eric V. Smith
Changes by Eric V. Smith : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue24454] Improve the usability of the match object named group API

2016-09-11 Thread Roundup Robot
Roundup Robot added the comment: New changeset ac0643314d12 by Eric V. Smith in branch 'default': Issue 24454: Improve the usability of the re match object named group API https://hg.python.org/cpython/rev/ac0643314d12 -- nosy: +python-dev ___ Python

[issue24454] Improve the usability of the match object named group API

2016-09-09 Thread Eric V. Smith
Eric V. Smith added the comment: Updated patch, with docs. I'd like to get this in to 3.6. Can anyone take a look? -- Added file: http://bugs.python.org/file44522/issue-24454-1.diff ___ Python tracker

[issue24454] Improve the usability of the match object named group API

2015-12-07 Thread Eric V. Smith
Eric V. Smith added the comment: Here's the patch. I added some more tests, including tests for ''.format_map(). I think the format_map() tests convince me that keeping None for non-matched groups makes sense. -- assignee: -> eric.smith keywords: +easy, needs review, patch stage: ->

[issue24454] Improve the usability of the match object named group API

2015-12-06 Thread Eric V. Smith
Eric V. Smith added the comment: I've been playing around with this. My implementation is basically the naive: def __getitem__(self, value): return self.group(value) I have the following tests passing: def test_match_getitem(self): pat = re.compile('(?:(?Pa)|(?Pb))(?Pc)?')

[issue24454] Improve the usability of the match object named group API

2015-06-15 Thread Raymond Hettinger
Raymond Hettinger added the comment: > but may be implementing access via attributes would > be even better? mo.groupnamespace().col or mo.ns.col? The whole point is to eliminate the unnecessary extra level. Contrast using DOM with using ElementTree. The difference in usability and readability

[issue24454] Improve the usability of the match object named group API

2015-06-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The disadvantage of supporting len() is its ambiguousness. Supporting indexing with group name also has disadvantages (benefits already was mentioned above). 1. Indexing with string keys is a part of mapping protocol, and it would be expected that other part

[issue24454] Improve the usability of the match object named group API

2015-06-15 Thread Matthew Barnett
Matthew Barnett added the comment: I agree that it would be nice if len(mo) == len(mo.groups()), but Serhiy has explained why that's not the case in the regex module. The regex module does support mo[name], so: print('Located coordinate at (%(row)s, %(col)s)' % mo) print('Located coordinat

[issue24454] Improve the usability of the match object named group API

2015-06-15 Thread Eric V. Smith
Eric V. Smith added the comment: I'd definitely be for mo['col']. I can't say I've ever used len(mo.groups()). I do have lots of code like: return mo.group('col'), mo.group('row'), mo.group('foo') Using groupdict there is doable but not great. But: return mo['col'], mo['row'], mo['foo'] would b

[issue24454] Improve the usability of the match object named group API

2015-06-15 Thread Barry A. Warsaw
Changes by Barry A. Warsaw : -- nosy: +barry ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pytho

[issue24454] Improve the usability of the match object named group API

2015-06-14 Thread Ezio Melotti
Ezio Melotti added the comment: > print(mo['col']) > print(len(mo)) This has already been discussed in another issue. As Serhiy mentioned, len(mo) and mo[num] would be ambiguous because of the group 0, but mo[name] might be ok. -- ___ Python tracke

[issue24454] Improve the usability of the match object named group API

2015-06-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: You can use mo.groupdict(). print('Located coordinate at (%(row)s, %(col)s)' % mo.groupdict()) print('Located coordinate at ({row}, {col})'.format_map(mo.groupdict())) As for len(mo), this is ambiguous, as well as indexing with integer indices. You sugge

[issue24454] Improve the usability of the match object named group API

2015-06-14 Thread Raymond Hettinger
New submission from Raymond Hettinger: The usability, learnability, and readability of match object code would be improved by giving it a more Pythonic API (inspired by ElementTree). Given a search like: data = 'Answer found on row 8 column 12.' mo = re.search(r'row (?P\d+) column (?P\d+