I don't see how it's more likely that people would remember to add a
`require=True` flag than to add `if m: raise RuntimeError("No match")`. The
problem here is people forgetting that a match can fail, not lack of a
means to handle that problem.

Paul

On Sat, 21 Oct 2023 at 11:38, Ram Rachum <r...@rachum.com> wrote:

> Hey,
>
> I bet this has been discussed before but I couldn't find it. I'd
> appreciate it if anyone could point me to that thread.
>
> I'm sick of seeing "AttributeError: 'NoneType' object has no attribute
> 'foo'" whenever there's a `re.match` operation that fails while the code
> expects it to succeed. What do you think about a flag `require` such that
> `re.match(pattern, string, require=True)` would either return a match or
> raise an exception with an actually useful message?
>
>
> Thanks,
> Ram.
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/PLF46RTMGJUIXRPXPLHZUPLTLGE47TQA/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BJ5R5MFLEDZFGKGHPLYBTPQJCCQTF5WZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to