[Python-3000] Fwd: Conventions for annotation consumers

Ron Adam rrr at ronadam.com
Sun Aug 20 05:17:28 CEST 2006


Paul Prescod wrote:
> On 8/19/06, *Ron Adam* <rrr at ronadam.com <mailto:rrr at ronadam.com>> wrote:
> 
> 
>     The callmeta decorator wouldn't provide any extra information itself,
>     all it does is decorate(wrap) the functions so that the meta data gets
>     called.  It activates the meta data calls.
> 
> 
> I think we're using the word "metadata" differently. In my universe, 
> metadata is a form of data and you don't "call" data. You just assert 
> it. I think that what you are trying to do is USE metadata as a form of 
> runtime precondition. 

Yes, I am extending the term in this case to include the details of 
implementing the meta-data.  If you describe something in enough detail 
it might as well python code.  And if it is python code, well why not 
make use of that?


Each of these describes "some info" to greater detail.

(1) "some info"


(2) some_info = "Brief description of some_info."


(3) some_info =
        """
           Detailed description of what
           some info is, and how to use it.

           Pseudo code to how to implement some_info property.
              (pseudo code ...)
        """

(4) some_info =
        """
           Detailed description of what
           some info is, and how to use it.

           # example python code to implement the
           # some_info property of x.
           def some_info_foo(x):
               ...
        """

(5) some_info(x):
        """
           some info - descripton of what some_info is.
        """
        <python code as the exact description of some_info>



This last one describes it so precisely it can actually be called if it 
is desired.  So why not use it?


> That's totally fine as long as we are clear that 
> there are many uses for metadata that do not require anything to 
> "happen" during the function's instantiation. A documentation annotation 
> or annotation to map to a foreign type system are examples. So the 
> decorator is allowed but optional. 

Yes, it is optional in this case too.  Just because it's callable, 
doesn't mean it has to be called to be used.  I could just as well use 
the doc attribute of the meta function, or the function name in any way 
I want and ignore the code completely.


> Given that that's the case, I guess I 
> don't understand the virtue of bringing decorators into the picture. 
> Yes, they are one consumer of metadata. Module-scoped functions are 
> another. Application scoped functions are another. Third party data 
> extraction programs are another. Decorators working with metadata are 
> just special cases of runtime processors of it.
> 
>  Paul Prescod

Decorators reduce repetition and put their labels before a function 
instead of after it. But they aren't required at *any* time because you 
can do the same thing without them, but they can help make the code more 
readable.

    @decorator
    def foo(x):
       # code

is the same as...

    def foo(x):
       # code
    foo = decorator(foo)

The name is repeated three times in the non-decorator version and 
because it is located after the function, it might not be noticed. Other 
than that, they are never required.  (Unless I'm unawares of special cases.)

(Not meaning to start a decorator discussion, just clarifying.)

Cheers,
    Ron







More information about the Python-3000 mailing list