classification
Title: _sre.SRE_Scanner object should have a fullmatch() method
Type: enhancement Stage: resolved
Components: Regular Expressions Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Gareth.Gouldstone, LewisGaul, aeros, ezio.melotti, mrabarnett, r.david.murray, serhiy.storchaka, twouters
Priority: normal Keywords:

Created on 2014-03-21 01:31 by Gareth.Gouldstone, last changed 2019-10-27 19:56 by serhiy.storchaka. This issue is now closed.

Messages (7)
msg214317 - (view) Author: Gareth Gouldstone (Gareth.Gouldstone) Date: 2014-03-21 01:31
I believe that the SRE_Scanner object should have a .fullmatch() method for consistency with other re pattern-matching behaviour.

>>> rex = re.compile('([^\\W\\d_]{1,2}[0-9]{1,2}[^\\d\\W_]?)[ \\t]*([0-9][^\\d\\W_]{2})')
>>> rex.scanner('bn20bs')
<_sre.SRE_Scanner object at 0x102006400>
>>> rex.scanner('bn20bs').search()                                           
<_sre.SRE_Match object; span=(0, 6), match='bn20bs'>
>>> rex.scanner('bn20bs').match()                                           
<_sre.SRE_Match object; span=(0, 6), match='bn20bs'>
>>> rex.scanner('bn20bs').fullmatch()                                           Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: '_sre.SRE_Scanner' object has no attribute 'fullmatch'
msg214320 - (view) Author: Gareth Gouldstone (Gareth.Gouldstone) Date: 2014-03-21 01:45
I also encountered issue 20998, which explains the convoluted [^\W\d_] in place of [a-zA-Z] as I was investigating why case-insensitivity and quantifiers would not work together.
msg214323 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-21 03:09
Scanner isn't a public interface, so the real enhancement here would be to make it one, in which case adding fullmatch would make sense.  I don't know if making it public is a good idea or not.
msg214337 - (view) Author: Gareth Gouldstone (Gareth.Gouldstone) Date: 2014-03-21 08:54
Scanner may not be a public interface but it is widely documented, not least on page 67 of the O'reilly Python Cookbook.

Even if Scanner is not made public, then surely it should maintain consistency with the public interfaces?
msg355468 - (view) Author: Lewis Gaul (LewisGaul) * Date: 2019-10-27 14:26
Scanner is not documented in CPython's own re documentation: https://docs.python.org/3/library/re.html#regular-expression-objects, so I'd say there's no obligation to maintain consistency with public APIs.

Is anyone able to make a call on whether this issue should be closed, or alternatively give some guidance on what work this issue should encompass?
msg355489 - (view) Author: Kyle Stanley (aeros) * (Python triager) Date: 2019-10-27 18:17
> Is anyone able to make a call on whether this issue should be closed, or alternatively give some guidance on what work this issue should encompass?

Added Serhiy to the nosy list, since he's an active maintainer for the re module.
msg355500 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-27 19:56
I concur with David. The SRE_Scanner object is not public. Its search() method is used for implementing finditer(). Its match() method could be useful for implementing a functional equivalent of \G in Perl. But I do not know a use case for its fullmatch() method.

If anybody provide a use case for SRE_Scanner.fullmatch() this issue can be reopened.
History
Date User Action Args
2019-10-27 19:56:21serhiy.storchakasetstatus: open -> closed
resolution: rejected
messages: + msg355500

stage: resolved
2019-10-27 18:17:00aerossetnosy: + aeros
messages: + msg355489
2019-10-27 18:14:33aerossetnosy: + serhiy.storchaka
2019-10-27 14:26:02LewisGaulsetnosy: + LewisGaul
messages: + msg355468
2014-03-21 08:54:46Gareth.Gouldstonesetmessages: + msg214337
versions: + Python 3.4
2014-03-21 03:09:03r.david.murraysetversions: + Python 3.5, - Python 3.4
nosy: + r.david.murray, twouters

messages: + msg214323

type: behavior -> enhancement
2014-03-21 01:45:26Gareth.Gouldstonesetmessages: + msg214320
2014-03-21 01:31:17Gareth.Gouldstonecreate