[Python-3000] Metaclass Vs Class Decorator

Guido van Rossum guido at python.org
Mon May 19 19:36:34 CEST 2008


You ought to ask this on c.l.py. The designers of the feature were
well aware of the similarities, and also of the differences, and the
decision was made to have both. Explaining this to every person who
asks is not a good use of our time.

On Mon, May 19, 2008 at 10:34 AM, paul bedaride <paul.bedaride at gmail.com> wrote:
> I think about it, and I think that it's two differents way of applying a
> similar thing,
>
> it's why I wonder, if this can't be good if metaclass and class decorator
> have the same
> interface, then we can use a class as a metaclass or as a decorator ??
>
> paul bedaride
>
> On Mon, May 19, 2008 at 6:10 PM, Guido van Rossum <guido at python.org> wrote:
>>
>> 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/)
>> _______________________________________________
>> Python-3000 mailing list
>> Python-3000 at python.org
>> http://mail.python.org/mailman/listinfo/python-3000
>> Unsubscribe:
>> http://mail.python.org/mailman/options/python-3000/paul.bedaride%40gmail.com
>
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/guido%40python.org
>
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list