[Python-3000] Metaclass Vs Class Decorator
Guido van Rossum
guido at python.org
Mon May 19 18:10:19 CEST 2008
On Sun, May 18, 2008 at 8:36 PM, Raymond Hettinger <python at rcn.com> wrote:
>>> It's why a want to know how to express the class decorator for making a
>>> comparison
>
> [Georg]
>>
>> A class decorator works exactly like a function decorator, that is,
>>
>> @foo
>> class X: ...
>>
>> is equivalent to
>>
>> class X: ...
>> X = foo(X)
>>
>> This should be all you need to know in order to write a class decorator.
>
> I concur.
Technically, that's true, but an example wouldn't hurt. Examples also
help understanding the motivation. Even the difference between class
decorators and metaclasses could be explained with examples. (E.g. a
metaclass that auto-registers its classes vs. a class decorator that
registers a class.)
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list