@decorator syntax is sugar, but for what exactly? (decorator libraries).

Anthony Baxter anthonybaxter at gmail.com
Sun Aug 8 15:50:16 CEST 2004

On Sun, 08 Aug 2004 09:32:21 -0400, Roy Smith <roy at panix.com> wrote:
> Anthony Baxter <anthonybaxter at gmail.com> wrote:
> Perhaps I'm just a luddite, but I don't actually use most of those
> features.  I have started playing around with iterators/generators, and
> find them very cool.

Fair enough. It usually took me a while to start using a new feature, 
but the ones I listed I find utterly invaluable - to the point where coding
against Python 2.1 I find annoying. I'd hate to have to code against 
Python 1.5.2, now that I'm used to having all the new tools.

> The single biggest improvement I see in the language since 1.5.2 is
> string methods!  After that, maybe augmented assignments (or whatever
> you call them; the ability to write "x += 1").

Good points on both - I forgot them in my list, but use them all the time.

> Most of the big improvements I've seen are in the library.  When did
> unitest get added?  I can't live without unittest.  I like the logging
> module, even if I think it's about twice as complicated as it should be.

There have been an enormous number of improvements to the stdlib,
true, but we're talking about changes to the language in this case.

> Speaking of libraries, Dan Bishop posted some interesting example of
> @memoize and @printreturns utility wrappers.  This leads me to think
> that a good way to leverage the idea of decorators would be a module of
> common utility functions which could be used as decorators by anybody.
> I'll call the module martha (since it supplies things used for
> decorating).  Does the proposed mechanism support something like (to use
> one of Dan's exmaples, written with two different syntaxen):

That might happen, but it's unlikely for 2.4. Give people time to use the new
tools, find out what works well and not so well, and standardise those.

> I'm even wondering if somehow decorators could be used for i18n?  The
> obvious problem there, is print is a statement not a function, and you
> can't decorate statements (or can you???).

Huh? You can only decorate function-or-methods. These can contain 
statements or expressions. And no, you can't decorate lambda. That 
would be an obscenity wrapped in a heresy and smacked with the 
ugly stick.


More information about the Python-list mailing list