[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-22 Thread David Mertz, Ph.D.
It's hard to overstate how "normal" a non-match is. A typical program might examine thousands of strings to identify the ten that match a pattern. Exceptions shouldn't be used for cases that are in no way exceptional. On Sun, Oct 22, 2023, 7:27 PM Greg Ewing wrote: > On 23/10/23 1:36 am, Juancar

[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-22 Thread Greg Ewing
On 23/10/23 1:36 am, Juancarlo Añez wrote: The *re* module is a black swan, because most of stdlib raises exceptions on invalid arguments or not being able to deliver. Most of the time, failure to match an re is not a programming error. Often it's perfectly normal. Sometimes it's the result of

[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-22 Thread Eric V. Smith via Python-ideas
On 10/21/2023 8:31 PM, Chris Angelico wrote: On Sun, 22 Oct 2023 at 11:29, MRAB wrote: I think what the OP wants is to have re.match either return a match or raise an exception. Yes, and my point is that simply attempting to access an attribute will do exactly that. It's not a silent failure.

[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-22 Thread Chris Angelico
On Mon, 23 Oct 2023 at 01:14, Juancarlo Añez wrote: > > The re module is a black swan, because most of stdlib raises exceptions on > invalid arguments or not being able to deliver. > This is a comparison function, and like every other comparison function, it signals its results with a return val

[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-22 Thread Juancarlo Añez
The *re* module is a black swan, because most of stdlib raises exceptions on invalid arguments or not being able to deliver. It's impossible to change *re* now, so wrapping the calls should be the right solution. -- Juancarlo Añez mailto:apal...@gmail.com On Sun, Oct 22, 2023 at 5:19 AM Stephen

[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-22 Thread Paul Moore
Just as a further note, it's perfectly possible to write a helper: def ensure_match(pattern, string): m = re.match(pattern, string) if m is None: raise ValueError(f"Provided string did not match {pattern}") return m If the project is concerned about failures to check the retur

[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-22 Thread Stephen J. Turnbull
Chris Angelico writes: > Why create a new argument, then mandate that you use it everywhere, > just to achieve what's already happening? "Newbies don't read code backwards very well" seems to be the point. While I'm not of the school that "I learned this painfully, so newbies should learn this