[Python-ideas] Python-ideas Digest, Vol 93, Issue 31
Łukasz Langa
lukasz at langa.pl
Thu Aug 14 03:51:37 CEST 2014
On Aug 13, 2014, at 6:33 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> On 08/14/2014 12:59 PM, Raymond Hettinger wrote:
>>
>> I would really like for the annotations to grow some way
>> to communicate exceptions as well as return types
>
> I'd hate for exception typing to be compulsory, though,
> since that turned out to be extremely annoying in Java.
>
> It would be even worse in Python, since there's no
> branch of the exception hierarchy corresponding to
> Java's RuntimeError for things that can be raised
> from anywhere.
As I understand it, that would serve mostly documentational purpose. The only analysis we could do on that would be to check if an exception is ever caught by the caller somewhere up the stack. This could already be done by finding “raise” statements and going from there.
But even with well annotated types that would be often hard to infer, limiting the usefulness of that analysis. Moreover, it wouldn’t surface problems when the code is using any type of framework that swallows exceptions to process them for the user.
So that leaves documentation. Now this information already lands in docstrings, which lacks the “one-obvious-way-to-do-it” feel. However, thanks to the hackiness of that approach, users don’t expect the provided list of exceptions to be comprehensive. That would change with a first-class syntax for them.
--
Best regards,
Łukasz Langa
WWW: http://lukasz.langa.pl/
Twitter: @llanga
IRC: ambv on #python-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140813/8192d2c2/attachment.html>
More information about the Python-ideas
mailing list