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'


Our brain that has been subjected to over a decade of Python work
automatically processes it, completely dismissing the 'strip' as a red
herring and concluding that a few lines above that line there was a regex
match that was expected to succeed but failed. Then we have to roll up our
sleeves and rerun this code with some instrumentation to find out what the
offending string was.

I propose to skip that entire exercise and go straight to:

re.NoMatchError: 'foobar' does not match pattern '^[0-9]+'


That would be so much nicer both for beginners and experienced developers.

What do you think about that?


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/4KHHPCY4QTFK6HDTRQTYQCFE4FOLEA42/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to