Using metaclasses to play with decorators.

Colin J. Williams cjw at sympatico.ca
Wed Jun 23 07:30:34 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.

OK, I'll ignore 'staticmethod', but could you tell me how

   def methodA(x, y) [noself]:
     return x + y

differs in substance from

   def methodA(self, y):
     return self + y

or
   def methodA(x, y):
     return x + y

What has been gained by the added syntactic clutter?

Colin W.
> 
> -- Dave
> 




More information about the Python-list mailing list