On 2023-10-21 21:15, Chris Angelico wrote:
On Sun, 22 Oct 2023 at 06:37, Ram Rachum <r...@rachum.com> wrote:
On Sat, Oct 21, 2023 at 10:30 PM Chris Angelico <ros...@gmail.com> wrote:
> I love that, but it mostly makes sense for "if there's a match do this, otherwise do that" where
most cases fall into "I'm absolutely sure there's a match here and here's what we should do with that
match", and when that "absolutely sure" fails, the proper way to deal with that is by raising an
exception.
>
Oh, you mean like AttributeError?
What I propose is like AttributeError in that they are both exceptions, but
unlike AttributeError in that it'll communicate the problem effectively in a
way that's easy to understand, especially by people who aren't Python experts.
When you and I see this:
AttributeError: 'NoneType' object has no attribute 'strip'
Which is strong evidence of a bug in your code. You're trying to tell
me that you want a way to enforce that, if the regex doesn't match,
it's a bug in your code. This seems to do that perfectly well.
If it's NOT a bug when the regex doesn't match, you have the standard
conditional form available. I'm not seeing a problem here.
I think what the OP wants is to have re.match either return a match or
raise an exception.
_______________________________________________
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/SCPAXBHEYNBRMMTBAX7A4DIO7UAVXBZN/
Code of Conduct: http://python.org/psf/codeofconduct/