from __future__ import function_annotations

I am just curiously wondering about the plans for introducing function annotations (PEP 3107). I could not find any information about this in the PEP, neither when I searched the mail archives. The way I see it this feature could be quite interesting to introduce as early as possible since I believe that there are quite a few tools that could benefit from this today. I could for example see Jython using function annotations for declaring methods that are supposed to be accessible from java code. This is done via annotations in the doc string today, and would be a lot clearer using function annotations. Jython could implement this use of function annotations without python supporting it, but that would make the code incompatible between python and Jython, which would be highly unfortunate. Therefore i propose that python adds support for function annotations in version 2.6 via from __future__ import function_annotations This would make the change as compatible as for example @decorators or the with-statement. /Tobias

On 4/11/07, Josiah Carlson <jcarlson@uci.edu> wrote:
Backporting annotations to 2.x was discussed in March (http://mail.python.org/pipermail/python-3000/2007-March/006107.html) to generally positive reception. The only possible hiccup would be that annotations wouldn't be supported for tuple parameters, since tuple params won't survive in 3.0 anyway. Collin Winter

On Apr 11, 2007, at 4:01 AM, Tobias Ivarsson 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:
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? -Tony

On 4/11/07, Tony Lownds <tony@pagedna.com> wrote:
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

On 4/11/07, Josiah Carlson <jcarlson@uci.edu> wrote:
Backporting annotations to 2.x was discussed in March (http://mail.python.org/pipermail/python-3000/2007-March/006107.html) to generally positive reception. The only possible hiccup would be that annotations wouldn't be supported for tuple parameters, since tuple params won't survive in 3.0 anyway. Collin Winter

On Apr 11, 2007, at 4:01 AM, Tobias Ivarsson 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:
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? -Tony

On 4/11/07, Tony Lownds <tony@pagedna.com> wrote:
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
participants (5)
-
Collin Winter
-
Josiah Carlson
-
Tobias Ivarsson
-
Tony Lownds
-
Tony Lownds