[Python-3000] Draft pre-PEP: function annotations
Phillip J. Eby
pje at telecommunity.com
Sat Aug 12 04:52:57 CEST 2006
At 03:39 PM 8/12/2006 -0700, Talin <talin at acm.org> wrote:
>Say I want to annotate a specific argument with two pieces of
>information, a type and a docstring. I have two metadata interpreters,
>one which uses the type information to restrict the kinds of arguments
>that can be passed in, and another which uses the docstring to enhance
>the generated documentation.
>Now, lets say that these two metadata interpreters were written by two
>people, who are not in communication with each other. Each one decides
>that they would like to "play nice" with other competing metadata.
>So Author A, who wrote the annotation decorator that looks for
>docstrings, decides that not only will he accept docstring annotations,
>but if the annotation is a tuple, then he will search that tuple for any
>docstrings, skipping over any annotations that he doesn't understand.
>(Although how he is supposed to manage that is unclear - since there
>could also be other annotations that are simple text strings as well.)
>Author B, who wrote the type-enforcement module, also wants to play nice
>with others, but since he doesn't know A, comes up with a different
>solution. His idea is to create a system in which annotations
>automatically chain each other - so that each annotation has a "next"
>attribute referring to the next annotation.
>So programmer C, who wants to incorporate both A and B's work into his
>program, has a dilemma - each has a sharing mechanism, but the sharing
>mechanisms are different and incompatible. So he is unable to apply both
>A-type and B-type metadata to any given signature.
Not at all. A and B need only use overloadable functions, and the problem
is trivially resolved by adding overloads. The author of C can add an
overload to "A" that will handle objects with 'next' attributes, or add one
to "B" that handles tuples, or both.
I've not bothered to reply to the rest of your email, since it depends on
assumptions that I've already shown to be invalid.
More information about the Python-3000