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

Steven Bethard steven.bethard at gmail.com
Tue Aug 10 18:55:29 CEST 2004

Andrew Durdin <adurdin at gmail.com> wrote in message news:<mailman.1361.1091977078.5135.python-list at python.org>...
> Well, I think I agree with the principle of limiting the expressions
> to dotted names. Some of the possibilities if you allow arbitrary
> expressions are pretty hairy:
> """
> Things someone might want to do, ordered roughly from most reasonable
> to least reasonable ;)
> @foo().bar()
> @foo or bar
> @mydecorators['foo']
> @lambda f: foo(f) or bar(f)
> """
> (from http://mail.python.org/pipermail/python-dev/2004-August/046673.html)

I don't remember who, but someone already mentioned that you can do
all of these things with the limited syntax if you really want to,
either with operator.* or eval:

@eval("foo or bar")
@operator.getitem(mydecorators, 'foo')
@eval("lambda f: foo(f) or bar(f)")

There are probably ways to avoid some of the evals, but I haven't
really thought too hard about it.


More information about the Python-list mailing list