[Python-ideas] Proposal: Use mypy syntax for function annotations
Nick Coghlan
ncoghlan at gmail.com
Fri Aug 22 02:40:37 CEST 2014
On 22 Aug 2014 03:27, "Antoine Pitrou" <antoine at python.org> wrote:
>
>
> 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 don't think it's possible to have "Pythonic" design by contract
(PyContracts makes a laudable effort, but I think its decorator based
syntax is cleaner than its annotation based one)
Decorators aren't going anywhere, so I'm comfortable with the idea of
complexity constraints on the type hint notation - anything that doesn't
fit into the type hint syntax can still go in a decorator, and get a handy
decorator name for readers to look up in the docs or on Google.
Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140822/78c58ca4/attachment.html>
More information about the Python-ideas
mailing list