On Sat, Sep 26, 2020 at 2:32 AM Oscar Benjamin
<oscar.j.benja...@gmail.com> wrote:
> I do agree but maybe that suggests a different role for annotated
> exceptions in Python. Rather than attempting to enumerate all possible
> exceptions annotations could be used to document in a statically
> analysable way what the "expected" exceptions are. A type checker
> could use those to check whether a caller is handling the *expected*
> exceptions rather than to verify that the list of *all* exceptions
> possibly raised is exhaustive.
>
> Consider an example:
>
> def inverse(M: Matrix) -> Matrix: raises(NotInvertibleError)
>     if determinant(M) == 0:
>         raise NotInvertibleError
>     rows, cols = M.shape
>     for i in range(rows):
>         for j in range(cols):
>             ...
>
> Here the function is expected to raise NotInvertibleError for some
> inputs.

Please no. Once again, this will encourage "handling" of errors by
suppressing them. Don't have anything that forces people to handle
exceptions they can't handle.

ChrisA
_______________________________________________
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/2CHBAJGWGO7S6P4CKWYG7ZZLTBZB2W35/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to