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

Ethan Furman ethan at stoneleaf.us
Sat Aug 16 01:46:55 CEST 2014


On 08/15/2014 03:49 PM, Barry Warsaw wrote:
> 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.

Sounds like what we *really* need is a decorator that will parse the docstring and fill in the annotations 
automatically.  :)

--
~Ethan~


More information about the Python-ideas mailing list