__metaclass__ and __author__ are already decorators
Paul Morrow
pm_mon at yahoo.com
Sat Aug 21 14:46:29 EDT 2004
Leif K-Brooks wrote:
> Paul Morrow wrote:
>
>> Thinking about decorators, and looking at what we are already doing in
>> our Python code, it seems that __metaclass__, __author__, __version__,
>> etc. are all examples of decorators. So we already have a decorator
>> syntax. What is the compelling reason to invent a new one? And if we
>> do, what's to become of the old one?
>> <snip>
>
>
> I've thought about something along the lines of your suggestion before,
> but it doesn't seem very Pythonic to assign special meaning to function
> variables with special names to me. It's essentially a new syntax, but
> disguised as an old syntax with an entirely different meaning.
We just need to stop thinking of them as local function variables.
Instead we should think of __xxx__ attributes as describing the function
itself (i.e. as a decorator would), as I believe that is almost always
the author's intention when he/she uses such names inside of a
function/method definition. He wants to say something about the
function (who wrote it, it's version, etc.), and is probably sad that it
has the side-effect of creating a local variable. So it probably
shouldn't have that side-effect anymore. It should create a function
attribute instead (not to be confused with a local variable).
For classes, it's much easier to accept this new way of looking at
__xxx__ attributes because it's consistent with our intention behind
them (as names for metadata rather than normal, inheritable class
attributes).
More information about the Python-list
mailing list