On Sat, Sep 26, 2020 at 2:32 AM Oscar Benjamin
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