Are decorators really that different from metaclasses...

Paul Morrow pm_mon at yahoo.com
Thu Aug 26 08:05:26 EDT 2004


Anthony Baxter wrote:
> 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.
> 

Ok.  Then let's jettison the baggage with the word metaclass and just 
call them 'magic attributes'.  It doesn't matter.  The essential point 
about them is that they almost /never have 'local variable' semantics/. 
  They are attributes of the object being defined.  That's the point I'm 
trying to drive home here.  When we use __xxx__ attributes, we are not 
intending to create local variables.  No.  We are making declarations.

> 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.
> 

Woah Man!  I thought you wanted special functionality to have special 
syntax, so that it really sticks out that we're doing something special?
It sounds like now you are /endorsing/ the use of normal looking syntax 
that does special things.

Personally, the look of the old '__implements__' syntax was vastly 
superior.  In an instant, an experienced pythonista could see that 
magic was being peformed on Foo.  That fact is obscured in the new 
'implements' syntax.

Wait.  Did I just argue your point from an earlier thread? :-)  See, we 
do (or at least 'did') agree on some things...



> 
>>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.

I don't need to debate that for my position to be valid.  How about from 
now on we just call it magic data?  That works fine for me.  As long as 
we're clear that it's not (intended to be) 'local data'.  That it has 
more of a declaration semantics.

Paul







More information about the Python-list mailing list