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/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4