[Python-ideas] Proposal to extend PEP 484 (gradual typing) to support Python 2.7
David Mertz
mertz at gnosis.cx
Mon Jan 11 16:49:50 EST 2016
>
> > An equivalent way to write this in Python 2 is the following:
> >
> > def embezzle(self, account, funds=1000000, *fake_receipts):
> > # type: (str, int, *str) -> None
> > """Embezzle funds from account using fake receipts."""
> > <code goes here>
>
> By using comments, the annotations would not be available at
> runtime via an .__annotations__ attribute and every tool would
> have to implement a parser for extracting them.
>
> Wouldn't it be better and more in line with standard Python
> syntax to use decorators to define them ?
>
> @typehint("(str, int, *str) -> None")
> def embezzle(self, account, funds=1000000, *fake_receipts):
> """Embezzle funds from account using fake receipts."""
> <code goes here>
>
I really like MAL's variation much better. Being able to see
.__annotations__ at runtime feels like an important feature that we'd give
up with the purely comment style.
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160111/c54269bb/attachment.html>
More information about the Python-ideas
mailing list