Using metaclasses to play with decorators.
David Fraser
davidf at sjsoft.com
Wed Jun 23 03:52:41 EDT 2004
David MacQuigg wrote:
> On Sun, 20 Jun 2004 14:48:23 -0400, "Colin J. Williams"
> <cjw at sympatico.ca> wrote:
>
>
>>I have yet to wrap my mind around decorators.
>
>
> Decorators are very simple. They are just a way to provide different
> forms of methods, without introducing a new keyword, or some other
> more awkward syntax.
>
> Say you wanted to define a method that didn't have 'self' as its first
> argument. You could add a new keyword to the language:
>
> noself methodA(x,y):
> return x + y
>
> Or you could add a "decorator" to the existing syntax:
>
> def methodA(x,y) [noself]:
> return x + y
>
> Change 'noself' to 'staticmethod' and you have one of the current
> proposals in PEP318.
>
> Don't get distracted by 'staticmethod' and other mumbo-jumbo
> terminology, and you should have no problem with decorators.
Aren't there other people around who would find
staticmethod methodA(x,y):
return x+y
a clearer and more helpful syntax than
def methodA(x,y) [staticmethod]:
return x + y
I've always wanted a
method A(x,y):
self.var += x*y
which automatically declared self as an initial parameter...
David
More information about the Python-list
mailing list