Are decorators really that different from metaclasses...

Anthony Baxter anthonybaxter at gmail.com
Thu Aug 26 03:43:35 EDT 2004


On Wed, 25 Aug 2004 07:20:17 -0400, Paul Morrow <pm_mon at yahoo.com> wrote:
> Not exactly, but it would include defining those.  One way to think
> about metadata is that it includes all information *about* an object,
> but no information *used by* the object.

See, for me, metadata is data about an object that is defined
explicitly as about the object. You can look at an object, and say
"Aha! It supports __getitem__, __iter__ and __len__, and is therefore
likely to be a sequence type object." This is not metadata - this is
something you've determined by looking at the object. __getitem__ and
friends *are* used by the object, and so can't be considered metadata.
I'd even say that __metaclass__ is not metadata in any sense of the
word, because it's *fundamental* to the class's workings.

Something like Zope3's Interfaces, which allow you to specify the
Interfaces that an object or class implements, are closer to metadata,
but note that even there, we've gone from an initial API of:

    class Foo:
        __implements__ = ( IFoo, )

to 
    class Foo:
        implements(IFoo)

... moving away from the double-under form to a more readable and
useful form. The new form allows for far more powerful and useful
behaviour, such as inheritence of interfaces from base classes.
Twisted has also moved from using the former style to the latter.
These are two _very_ large bodies of code, with a lot of very clueful
people working on them - and they found that the magic double-under
name was inferior to an explicit call syntax.

> If we were to have a conversation about this conversation, then we would
> be having a "meta-conversation."  /metadata/ is data that describes
> data.  metadata for a function would be data that describes the
> function; data *about* the function as opposed to data *used by* the
> function.  For example:
> 
>     def circumference(diameter):
>        """ This is a docstring.  It's metadata for this function. """
>        __author__ = 'Paul Morrow'      # more metadata
>        pi = 3.14                       # not metadata
>        return pi * diameter

There are a small number of double-under names that are used for
metadata - most of them are automatically inserted by Python
automatically. The overwhelming number of double-under names are not
metadata in any way.



More information about the Python-list mailing list