PEP 3107 Function Annotations for review and comment

BJörn Lindqvist bjourne at gmail.com
Fri Dec 29 19:09:38 EST 2006


On 12/29/06, Tony Lownds <tony at pagedna.com> wrote:
> Rationale
> =========
>
> Because Python's 2.x series lacks a standard way of annotating a
> function's parameters and return values (e.g., with information about
> what type a function's return value should be), a variety of tools
> and libraries have appeared to fill this gap [#tailexamp]_.  Some
> utilise the decorators introduced in "PEP 318", while others parse a
> function's docstring, looking for annotations there.
>
> This PEP aims to provide a single, standard way of specifying this
> information, reducing the confusion caused by the wide variation in
> mechanism and syntax that has existed until this point.

I think this rationale is very lacking and to weak for such a big
change to Python. I definitely like to see it expanded.

The reference links to two small libraries implementing type checking
using decorators and doc strings. None of which to seem to be very
popular in the Python community. Surely, those two libraries *alone*
can't be enough of a motivation for this? To me, it is far from
self-evident what purpose function annotations would serve.

I also wonder why a very obtrusive syntax addition is needed when it
clearly is possible to annotate functions in today's Python. Why is
syntax better than just adding a function annotation decorator to the
standard library?

    @annotate(a = int, b = dict, c = int)
    def foo(a, b, c = 5):
        ...

Are decorators to ugly?

-- 
mvh Björn



More information about the Python-list mailing list