[Python-ideas] [Python-3000] PEP 3107 Function Annotations: overloadable ->

Josiah Carlson jcarlson at uci.edu
Tue Jan 2 02:39:17 CET 2007

"Guido van Rossum" <guido at python.org> wrote:
> On 1/1/07, Tony Lownds <tony at pagedna.com> wrote:
> > Is anyone against "->" overloadable as __returns__ /__rreturns__
> > with no semantics for existing types?
> I suggest that you question *really* *hard* whether it's worth it.
> We'd be introducing two very different syntactic uses for '->'. I
> chose this operator to signify function return annotation specifically
> because it *does't* have another meaning in Python. (My first choice
> would've been ':', which is mostly a delimiter that derives its
> meaning from context, like ',', but that would've introduced too much
> syntactic ambiguity.

Just to clarify, the only place '->' is allowable is in the case of
function annotations...

    def <name>(<args...>) -> <annotation>:

Given a reading of version 53169 of PEP 3107, I see no reason to even
offer a __returns__ attribute, automatic method call, etc.  PEP 3107
already defines the annotation to be specified as a dictionary of named
argument names, with a key of 'return' for the annotation of the return
annotation.  Is there any reason why this isn't sufficient?

Even in the context of the signature PEP 362, there is no need for
__returns__, as an annotation-consuming library would check the
signature object for argument annotations, and the func_annotations
dictionary for the 'return' key for any return annotations.

 - Josiah

More information about the Python-ideas mailing list