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

Antoine Pitrou antoine at python.org
Thu Aug 21 19:24:15 CEST 2014


Le 21/08/2014 12:15, Nick Coghlan a écrit :
>
> Given:
>
>      Sequence[Number]
>      Sequence[Number|None]
>
> There's still at least three options for extending the syntax even further:
>
>      Sequence[Number](EXPR)
>      Sequence[Number:EXPR]
>      Sequence[Number,EXPR]
>
> You'd probably want to use strings at that point, for the same reasons
> PyContracts does. For example:
>
>      Number,"N>0" # Positive number
>      Sequence[Number,"N>0"] # Sequence of positive numbers
>      Sequence[Number],"N>0" # Non-empty sequence

All of those are horrible and un-Pythonic, though.
Python has one of the most powerful and user-friendly function call 
syntaxes around, why reinvent something clearly inferior and alien?

 > I doubt we'll ever get to that point, though. Type hinting and runtime
 > assertions aren't the same thing.

It's less about defining all those use cases up front and more about not 
painting ourselves in a corner, though.

Regards

Antoine.




More information about the Python-ideas mailing list