[Python-3000] Draft pre-PEP: function annotations
Phillip J. Eby
pje at telecommunity.com
Sun Aug 13 04:21:47 CEST 2006
At 05:05 PM 8/12/2006 -0700, Paul Prescod wrote:
>It seems to me that there are two very reasonable positions being
>expressed. Is the following (non-normative) text a compromise?
>
>"In order for processors of function annotations to work interoperably,
>they must use a common interpretation of objects used as annotations on a
>particular function. For example, one might interpret string annotations
>as docstrings. Another might interpet them as path segments for a web
>framework. For this reason, function annotation processors SHOULD avoid
>assigning processor-specific meanings to types defined outside of the
>processor's framework. For example, a Django processor could process
>annotations of a type defined in a Zope package, but Zope's creators
>should be considered the authorities on the type's meaning for the same
>reasons that they would be considered authorities on the semantics of
>classes or methods in their packages. This implies that the interpretation
>of built-in types would be controlled by Python's developers and
>documented in Python's documentation. This is just a best practice.
>Nothing in the language can or should enforce this practice and there may
>be a few domains where there is a strong argument for violating it ( e.g.
>an education environment where saving keystrokes may be more important
>than easing interopability)."
I mostly like this; the main issue I see is that as long as we're
recommending best practices, we should recommend using tell-don't-ask (via
duck typing protocols, adaptation, or overloaded functions) so that their
libraries can be enhanced and extended by other developers.
>"In Python 3000, semantics will be attached to the following types:
>basestring and its subtypes are to be used for documentation (though they
>are not necessarily the exclusive source of documentation about the type).
>List and its subtypes are to be used for attaching multiple independent
>annotations."
I'm not sure why we would use strings for documentation, but I'm not
opposed since it eliminates the question of multiple interpretations for
strings.
>(does chaining make sense in this context?)
I don't know if I know what you mean by "chaining". Good use of
tell-don't-ask means that any interpretation of annotations nested in other
annotations would be defined by the enclosing annotation (or in an overload
for it).
More information about the Python-3000
mailing list