[Python-Dev] __metaclass__ and __author__ are already decorators
Phillip J. Eby
pje at telecommunity.com
Sat Aug 21 18:54:37 CEST 2004
At 12:29 PM 8/21/04 -0400, Paul Morrow wrote:
>[I posted this on comp.lang.python.general but I'm not sure how many of
>the folks here read that newsgroup, so my apologies if you're seeing this
>twice.]
>
>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.
The items you describe are not decorators, they are attributes. The
current syntax for decorators is 'x = decorator(x)'.
> def baz(self, a, b):
> """ This describes the baz method. """
> __synchronized__ = True
> __returns__ = None
> __author__ = 'Neville Shunt'
> # body of baz goes here...
This syntax already has a different and conflicting meaning in today's
Python. A different such syntax:
[synchronized(), returns(None), author("Neville Shunt")]
def baz(self, a, b):
""" This describes the baz method. """
# body of baz goes here...
has already been rejected on the basis that this too has meaning in today's
Python, and that the syntax produces "spooky action at a distance". That
is, it's "magical" that the function calls affect the definition below.
Following this logic, expecting assignments to magic names contained within
a function's body to magically invoke decorator functions with different
names *before and outside the block* where those names are assigned to in
the code, seems far less likely to be considered acceptable.
More information about the Python-Dev
mailing list