[Python-3000] Conventions for annotation consumers (was: Re: Draft pre-PEP: function annotations)

Jim Jewett jimjjewett at gmail.com
Tue Aug 15 00:22:45 CEST 2006

On 8/14/06, Collin Winter <collinw at gmail.com> wrote:
> On 8/14/06, Paul Prescod <paul at prescod.net> wrote:

> The problem with using lists is that its impossible for non-decorator
> annotation consumers to know which element "belongs" to them.

The ones whose type they own -- which is why I see at least some
parallel to exceptions, and its inheritance based semantics.

    def f(a:[mytype("asdfljasdf"),
             "a string",
        """Example of long compound annotations

Maybe annotations this size should just be restricted to Signature modification
instead of allowing them in the actual declaration?  At least by style guides?

By the defined meaning of list, these are 5 independent annotations.

Whoever defined mytype controls the meaning of the mytype annotations;
anyone not familiar with that package should ignore them (and hope
there were no side effects in the expressions that generated them).

zope.mypackage controls that annotation; anyone not familiar with that
product should ignore it (and hope there were no side effects ...)

"a string" and 15 are builtin types -- so their semantics are defined
by core python, which says that they are documentation only --
stripping them off or changing them wouldn't break a properly written

> Here, multiple_annotations assumes that the annotation dicts are keyed
> on consumer.__name__;

Too many consumers will call themselves "wrapper" or some such.  You
should key on the actual type object -- in which case you probably
want isinstance to support subtypes.


More information about the Python-3000 mailing list