[Python-ideas] Proposal: Use mypy syntax for function annotations
Antoine Pitrou
antoine at python.org
Fri Aug 22 03:24:17 CEST 2014
Le 21/08/2014 20:40, Nick Coghlan a écrit :
> On 22 Aug 2014 03:27, "Antoine Pitrou"
> <antoine at python.org
> <mailto: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
We're not talking about design by contract, we're talking about type
annotations. "A list of X integers" isn't exactly an extremely
complicated notion. We shouldn't need weird convoluted syntaxes to
express it.
Regards
Antoine.
More information about the Python-ideas
mailing list