[Python-ideas] Python-ideas Digest, Vol 93, Issue 31

Juancarlo Añez apalala at gmail.com
Thu Aug 14 16:10:51 CEST 2014


On Thu, Aug 14, 2014 at 7:08 AM, Christian Heimes <christian at python.org>
wrote:

> As I tried to explain earlier neither users nor tools are able to
> analyze code like builtin types and functions. Exception annotations
> could help IDEs to figure out what kind of exception could be raised.
> Does it sound better to you?
>

It does, but it remains that annotations about exceptions will probably be
inconsistent or incomplete:

   1. If the function is changed, the annotation will remain valid even if
   the mentioned exceptions are not raised (this is the typical doc-comment
   problem).
   2. The annotation cannot be validated unless the raisables of called
   functions (objects, actually) are analysed.

Dealing with #2 means going the Java way and promoting incorrect exception
handlers throughout.

Not dealing with #2 means that the annotations are for documentation
purposes only, so the same information can go in the doc-comment.

This situation is unlike that for the proposed type signatures, because the
intent for those is that they are strictly verified (with mypy or some
other).

In short, an exceptions signature would amount to:

"This function may or may not raise the listed exceptions, and it may also
raise other exceptions not in the list.".

Yet, #2 can be dealt with by not being strict, and issuing warnings when
things seem broken, taking note that the Python callables that can raise
exceptions are not only functions and methods, but anything for which
callable(o)==True.

Cheers,

-- 
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140814/7637427b/attachment-0001.html>


More information about the Python-ideas mailing list