[Python-Dev] A decorator syntax not yet mentioned (I think!)
John Marshall
John.Marshall at ec.gc.ca
Wed Aug 11 17:16:57 CEST 2004
How about the following, which I am almost positive
has not been suggested:
-----
class Klass:
def __init__(self, name):
self.name = name
deco meth0:
staticmethod
def meth0(x):
return x
deco meth1:
classmethod
def meth1(cls):
return cls
deco sayhello:
funcattrs(name='GvR', language='python')
log(file='func.log')
def sayhello(self):
print 'hello python world'
-----
1) The decorators clearly apply to a specific method/function,
therefore there is no need to do any stack pushing in memory
until the method/function definition is done.
2) The decorators are "outside" of the method/function they
decorate:
a) which will please those who want the outside location
b) will not be folded within the function
c) folding on the decorators can be done so that the
def is not obfuscated
d) can be located anywhere in the code--but most likely
before the "def ...()"
3) The sequence in which the decorators are applied is just
like code would be--this is certainly intuitive given
that we are writing code.
This approach could also be applied to classes in case
decorators should ever be extended to them:
-----
deco Klass:
doc("This is a class to ...")
class Klass:
:
:
-----
Any comments?
John
More information about the Python-Dev
mailing list