PEP 3107 Function Annotations for review and comment

John Roth JohnRoth1 at jhrothjr.com
Sun Dec 31 11:23:15 EST 2006


Tony Lownds wrote:
> > First, it only handles functions/methods. Python FIT needs
> > metadata on properties and assignable/readable attributes
> > of all kinds. So in no sense is it a replacement. Parenthetically,
> > neither is the decorator facility, and for exactly the same reason.
> >
>
> I can't argue against docstrings and maybe annotations on attributes,
> I'd like them myself. That should be a separate PEP because the scope
> of this one is Function Annotations.
>
> The syntax for function annotations has been much more thoroughly
> discussed than for annotations on attributes. See Guido's blog and
> other references in the PEP.

Syntax is always an issue. Looking at the history of annotations
shows that people seem to prefer using a comment mechanism.
This goes along with the notion of supplying minimal mechanism
until you see what the actual usage is going to be.

As far as I'm concerned, an annotation mechanism has to have
several properties:

1. The annotation data needs to be available at run time without
having the source available.

2. It needs to be syntax checkable by a mechanism supplied
by the author of the annotation schema. I'd suggest a hook
at the back end of import, since this doesn't get in the
way of the compiler.

The converse of this, of course, is that neither the language
nor the compiler needs to have any idea of the actual syntax.
This provides maximal freedom to experiment.

3. It needs to have a convention that will allow authors of
different schemas to stay out of each other's way.

Docstrings almost manage this. While they're certainly
available at run time (at least if you don't compile in a
way that strips them out) you can only have one in any
module, class or method. This means you can't always
put them where you want them, that is, close to the
item that they're annotating. Parenthetically, I'd note that
adding docstring capabilities to properties was a definite
step forward.

John Roth

> 
> Thanks for the feedback from everyone so far,
> -Tony




More information about the Python-list mailing list