[Python-ideas] Proposal: Use mypy syntax for function annotations

Barry Warsaw barry at python.org
Sat Aug 16 00:49:09 CEST 2014


On Aug 14, 2014, at 11:33 AM, Ethan Furman wrote:

>> def frobinate(x, y):
>>      """Return the frobinated x and y.
>>
>>      Some more text goes here. Perhaps lots of text.
>>
>>      :param x: Spam
>>      :param y: Eggs
>>      :return: Breakfast
>>      """
>
>Sure, keeping that info in the annotations makes more sense, but I'd rather
>see it in the doc string instead of ruling out all other possible uses of
>annotations -- particularly for something that's supposed to be /optional/.

Docstring annotations almost by definition can contain more information useful
to the human reader than type annotations can, especially if you carefully use
the reST-ish epydoc convention of both :param: and :type:.  The latter
contains the type annotation (which an automated system could utilize) while
the former contains the exposition (for the benefit of the human reader).
It's the explanations that are missing from any type annotations.

I suppose you could intersperse comments with your type annotations, resulting
in a long multiline function signature.  I doubt that would be a readability
improvement.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140815/353bc1fd/attachment.sig>


More information about the Python-ideas mailing list