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

David Eppstein eppstein at ics.uci.edu
Tue Aug 10 19:02:30 CEST 2004

In article <d11dcfba.0408100855.3ac0bf9c at posting.google.com>,
 steven.bethard at gmail.com (Steven Bethard) wrote:

> 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().bar()")
> @eval("foo or bar")
> @operator.getitem(mydecorators, 'foo')
> @eval("lambda f: foo(f) or bar(f)")

A little more cleanly like this?

def id(x): return x

@id(foo or bar)
@id(lambda f: foo(f) or bar(f))

David Eppstein
Computer Science Dept., Univ. of California, Irvine

More information about the Python-list mailing list