Recent related discussion:

https://mail.python.org/archives/list/python-ideas@python.org/thread/MXPCNEAWXWJPOHB3DC3QW3S3ZPOFSM4Q/

On Fri, May 1, 2020 at 8:53 AM Ram Rachum <r...@rachum.com> wrote:

> Hi,
>
> Here's something I wanted in Python for many years. If this has been
> discussed in the past, please refer me to that discussion.
>
> On one hand, it's something that I can't imagine the python-dev community
> supporting. On the other hand, it would maintain backward compatibility.
>
> I wish there were a 100 more built-in exceptions in Python, that will be
> very specific about what went wrong.
>
> If I do this:
>
>     >>> x, y = range(3)
>
> I know it'll raise a ValueError, because I've memorized that, but it did
> take me a few years to remember where I should expect ValueError and where
> I should expect TypeError.
>
> It would be nice if the operation above raised UnpackingOverflowError,
> which will be a subclass of UnpackingError, along with
> UnpackingUnderflowError.  UnpackingError can be a subclass of ValueError,
> for backward compatibility.
>
> Similarly, if I did this:
>
>     >>> def f(x, y): return x + y
>     >>> f(1)
>
> I would get a TypeError. Would be a lot cooler if I got
> MissingArgumentsError, which would be a subclass of SignatureError, which
> would be a subclass of TypeError.
>
> There are 2 reasons I want this:
>
> 1. When I'm writing a try..except clause, I want to catch a specific
> exception like MissingArgumentsError rather than ValueError or TypeError.
> They're too ubiquitous. I don't want some other unexpected failure
> producing the same ValueError and triggering my except clause.
>
> 2. When I get an error, especially from some shitty corporate system that
> truncates the traceback, I want to get as many hints as possible about what
> went wrong.
>
> It's true that today, most Python exceptions have good text in their
> message, like "TypeError: f() missing 1 required positional argument: 'y'".
> But that isn't guaranteed everywhere, and specific exception types could
> help.
>
>
> What do you think?
>
>
> 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/XZXWXICKS2RCQLLX73NJOWCJPRY7IUX2/
> 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/ZVX6Q6GFRVN6X43WZEAOBCDZTWJH56U6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to