[Python-ideas] Proposal: Use mypy syntax for function annotations
Stephen J. Turnbull
stephen at xemacs.org
Fri Aug 15 04:15:10 CEST 2014
Steven D'Aprano writes:
> > 2) PEP 3107 only specifies arguments and return values but not
> > exceptions that can be raised by a function. Java has the "throws"
> > syntax to list possible exceptions:
> >
> > public void readFile() throws IOException {}
>
> I understand that this is called a "checked exception" in Java. I also
> understand that they are hated and derided
Sure, but that's because it's hard for a human to guess what might
happen down in lower-level functions, let alone 3rd-party libraries
and the runtime -- and your program fails if you guess wrong.
Maybe the fact that type-checking is going to be optional mitigates
that.
I suspect it's not terrible useful, but another idea is to invert the
sense, i.e. say what exceptions the function believes it handles, and
therefore cannot be raised.
> Perhaps with a few years of experience, we might be able to extend this
> to exceptions without making the same mistakes as Java's checked
> exceptions, but I wouldn't rush into it.
+1 to that!
More information about the Python-ideas
mailing list