[Python-Dev] Re: __metaclass__ and __author__ are already
"Martin v. Löwis"
martin at v.loewis.de
Sun Aug 22 09:21:39 CEST 2004
Paul Morrow wrote:
>> The items you describe are not decorators, they are attributes. The
>> current syntax for decorators is 'x = decorator(x)'.
> In today's Python that's of course true, but these 'attributes' are used
> to supply meta info about the class. They *describe* the class. They
> are never intended to be inherited by instances of the class. So in
> this sense, they are very much more like decorators than (normal) class
No, that makes them completely unlike function decorators. Function
decorators do not describe something, they modify something (namely,
the thing that is bound to the function's name).
Some attributes have a run-time meaning, like __metaclass__; others,
like __author__, have not. Unfortunately, the meaning of __metaclass__
is conceptually different from decorators: the metaclass is evaluated
*before* the class is constructed; the decorators are evaluated
*after* the function is constructed.
> So providing definitions for __xxx__ attributes is not done for the same
> purpose as the other attributes. They are special. Therefore, let's
> formally acknowledge that and call them 'decorators'.
I acknowledge that they are special, and call them "special attributes".
I won't call that decorators, because that means something else.
> 2. All magic methods in today's Python are invoked 'magically' (are
> called indirectly; not called directly by any user code).
Correct. For each special attribute, the interpreter needs advance
knowledge of the name of the attribute. Not so for decorators:
the interpreter does not need advance knowledge - you can define
your own function decorators, and Python will support them because
of the leading @.
More information about the Python-Dev