[Python-Dev] @decoration of classes

Josiah Carlson jcarlson at uci.edu
Thu Mar 24 23:55:49 CET 2005

Jim Jewett <jimjjewett at gmail.com> wrote:
> Josiah Carlson:
> > I just noticed that decoration of classes was not included with the
> > @decoration syntax that made it into Python 2.4. ...
> > Is the fact that it didn't make it into 2.4 due to a pronouncement 
> Yes, but it wasn't a permanent decision, and I don't think
> he used the magic word "pronounce".
> Adding class decoration later is not difficult.
> Retracting class decoration later would have been impossible.
> Therefore Guido decided for version 2.4, but left the question
> open for the unspecified future.  Changing it would take 
> arguments stronger than symmetry or "why not?", so it 
> probably won't change for 2.5, but if you have a compelling
> use case ...
> (Mine have all been using an object as a callable -- basically
> replacing a function.  The itch hasn't been strong enough to
> bother me.)

I think of it like this; I learned restructured text because I wanted to
learn a markup for writing things that didn't encumber the writing.  At
a certain point, it became necessary for me to learn TeX.

Does that mean that reST has no use to me now that I know TeX?  Of
course not, reST still has its place, and when I write documentation, I
write it in reST.  When I begin to write academic papers, I write it in
reST, then later translate it to TeX, because that is the language of
typeset academic writings.  I could write it first in TeX, but the
notation can get cumbersome, and reST is still valid (whether or not it
survives the decade; I still have the source, a python interpreter, and
an emulator).

While I have not used it often, I have done the equivalent of decorating
classes; it is as natural (though perhaps not quite as useful initially)
as decorating functions, and as simple as writing in reST.  I also
happen to know a bit about using metaclasses, though tend to shy away
from it, because it feels cumbersome.

Can you do everything with TeX that you can with reST?  Of course.  Does
it make reST any less valid or desireable to use?  Of course not.

Can you use a metaclass to do anything you could do with class
decorators?  Probably (I don't know the corner cases that would make it
not so). Does that mean that class decoration is any less valid or
desireable to use?  Of course not.  Does that mean that it should have a
syntax?  That is the question.

I personally choose class decoration over metaclasses (when possible)
because I feel it is easier to use.  However, as my use case has not
been compelling enough in the past, I is certainly not compelling enough
now. If someone cares more about this, who has more influence and wants
to continue the conversation; feel free, but I'll still use Python
tomorrow without class decoration syntax.

 - Josiah

P.S. You know, it's kind of like putting sprinkles on a banana split.
Some people like the sprinkles, some people don't.  Some people complain
when they are there, some people can't eat it without the sprinkles. But
you know what?  You've got the banana split already, enjoy it.  If you
get the sprinkles, so be it, but hassling the waitress for sprinkles is
a pretty rude thing to do to a woman in an ice cream parlor.

More information about the Python-Dev mailing list