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

Ethan Furman ethan at stoneleaf.us
Thu Aug 14 20:33:45 CEST 2014


On 08/14/2014 11:15 AM, Steven D'Aprano wrote:
>
> I like the annotation syntax. I'm not completely convinced that the mypy
> syntax is mature enough to bless, but the basic idea of type annotations
> is pretty common in dozens of languages. I think you are in a tiny
> minority if you think that putting the type declaration right next to
> the parameter make it *less* clear that putting the type declaration in
> a completely different part of the code.
>
> # the type is together with the parameter
> def frobinate(x: Spam, y: Egg)->Breakfast:
>
> # the type declaration and parameter are distantly apart
> 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/.

--
~Ethan~


More information about the Python-ideas mailing list