[Python-ideas] Conventions for function annotations
Thomas Kluyver
thomas at kluyver.me.uk
Tue Dec 4 17:51:13 CET 2012
On 4 December 2012 16:43, Jasper St. Pierre <jstpierre at mecheye.net> wrote:
> The local decorator influence might work, but that has the problem of only
> being able to be used once before we fall back to the old method. Would you
> rather:
>
> @tab_expand(filename=glob('*.txt'))
> @types
> def read_from_filename(filename:str, num_bytes:int) -> bytes:
> pass
>
> or
>
> @tab_expand(filename=glob('*.txt'))
> @types(filename=str, num_bytes=int, return_=bytes)
> def read_from_filename(filename, num_bytes):
> pass
>
> For consistency's sake, I'd prefer the latter.
>
Using the decorator decorator I posted (https://gist.github.com/4189289 ),
you could use these interchangeably, so the annotations are just a
convenient alternative syntax for when you think they'd make the code more
readable.
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121204/82d15ffc/attachment.html>
More information about the Python-ideas
mailing list