[Python-Dev] Re: 2.4a2, and @decorators
David Eppstein
eppstein at ics.uci.edu
Tue Aug 3 06:28:52 CEST 2004
In article <110DAF75-E504-11D8-8D12-000A95A50FB2 at fuhm.net>,
James Y Knight <foom at fuhm.net> wrote:
> > @ foo or bar
> > def f(): ...
> >
> > you can write
> >
> > deco = foo or bar
> > @deco
> > def f(): ...
>
> An even better workaround is to write:
> def d(arg): return arg
>
> @d(foo or bar)
> def f(): ...
>
> However, it seems as if this restriction creates a new class of
> expression for no gain. It is true enough that *most* python
> expressions aren't useful to write after a @, but that's also true of a
> lot of other places an expression can be used (e.g. before a () of a
> function call. A list comprehension can never result in a callable
> object. An arithmetic operation usually won't.).
As you say, there aren't a lot of types of Python expression that return
callables. The main thing this restriction seems to prevent is @lambda,
and I think preventing that is a good thing. The other possibility that
comes to mind is @functable[index], but I'd have to see a use case
before worrying too much that it's not allowed.
--
David Eppstein
Computer Science Dept., Univ. of California, Irvine
http://www.ics.uci.edu/~eppstein/
More information about the Python-Dev
mailing list