[Python-Dev] @decoration of classes

Nick Coghlan ncoghlan at iinet.net.au
Thu Mar 31 03:31:54 CEST 2005

Delaney, Timothy C (Timothy) wrote:
> class factory:
>     @register
>     def __call__(self):
>         pass
> Just as an additional data point - obviously not applicable in all
> cases.

Yep, and it's obviously possible to do that now with just function decorators. 
Getting my head around what that actually *does* is a little trickier, though 
(as near as I can tell, it will register a standalone function named __call__, 
with nothing linking it to the containing class).

What a class decorator allows is the registration of the whole process of 
invoking the metaclass and hence __new__ and __init__ as a single unit.

Anyway, I don't particularly feel the lack of class decorators, but I thought I 
should mention this (perhaps small) category of non-transforming decorators as a 
situation where class decoration would make more sense to me than using a metaclass.


Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia

More information about the Python-Dev mailing list