Are decorators really that different from metaclasses...

Anthony Baxter anthonybaxter at gmail.com
Tue Aug 24 23:02:47 EDT 2004


On Tue, 24 Aug 2004 12:29:38 -0400, Paul Morrow <pm_mon at yahoo.com> wrote:
> ....that they warrant an entirely new syntax?  It seems that they are
> very similar in a very significant way --- they alter the default
> behavior of something.  IMO, it's not a stretch to say that they
> 'parallel' metaclasses; that they are to functions/methods what
> metaclasses are to classes.  So why don't they share a similar syntax?

No. Function decorators are to functions as class decorators are to classes.

Class decorators are not in 2.4, because you can do most things you'd
do with a class decorator by using a metaclass, but in a completely
different way. In my opinion, class decorators _should_ be in 2.4,
because they're a much saner way to handle many things that require a
metaclass today.

They don't "alter the default behaviour". A metaclass allows the user
to specify an object that builds classes in a new way. A decorator
allows the user to specify a way to transform the already built
function (or class, for class decorators).

Anthony



More information about the Python-list mailing list