[Python-ideas] from future import function_annotations (original) (raw)
Collin Winter collinw at gmail.com
Wed Apr 11 18:16:02 CEST 2007
- Previous message: [Python-ideas] from __future__ import function_annotations
- Next message: [Python-ideas] from __future__ import function_annotations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4/11/07, Tony Lownds <tony at pagedna.com> wrote:
Function annotations PEP is accepted and code has been checked in to p3yk. I don't think there would be much support for the syntax in 2.6, but I could be wrong. A more palatable compatibility strategy may be to introduce a decorator that sets function.annotations, so that these two function definitions would have equivalent annotations:
>>> @annotate(int, int, returns=int) ... def gcd1(m, n): ... etc >>> def gcd2(m: int, n: int) -> int: ... etc It's easier for a decorator to be compatible with run-time semantics, and more likely to avoid syntax questions, than embedding the annotattions in docstrings. Source code conversion (2to3) could change the @annotate decorator form to the in-line function form. Tools could be written to use either annotation set. What do y'all think?
Speaking only to the part about 2to3, that sort of conversion would be a pain in the ass to write. Even if the @annotate decorator were keyword-args only (allowing positional args complicates the implementation more than you would expect), it would still probably be quicker/easier/more accurate just to port the 3.0 annotations implementation to 2.6.
Collin Winter
- Previous message: [Python-ideas] from __future__ import function_annotations
- Next message: [Python-ideas] from __future__ import function_annotations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]