[Python-ideas] Decorator syntax restriction

Stephen J. Turnbull stephen at xemacs.org
Sat Oct 10 13:15:26 CEST 2009

geremy condra writes:
 > On Sat, Oct 10, 2009 at 2:12 AM, Carl Johnson
 > <cmjohnson.mailinglist at gmail.com> wrote:

 > > One might also write:
 > >
 > > @debug if debug else lambda f: f
 > > def f....
 > >
 > > Is that too confusing though? My instinct says it's fine, but maybe
 > > others disagree. Still, I think the restriction should be taken off.
 > > We're all adults, etc.
 > >
 > >  --Carl
 > I'm moving towards +1 on this- the above looks very useful to
 > me.

Does either of the suggestions for debug actually "work",
stylistically?  Specifically, consider the preparatory code required.
This looks awful to me:

def debug (f):
    return decorate_for_debug(f)
debug = False                    # gag, retch, puke

@debug if debug else lambda f: f
def foo():

The comment may be *little* extreme, but surely that's not very
beautiful in your eyes?  Isn't

debug = False
def instrument (f):
    return decorate_for_debug(f) if debug else f

def foo():

preferable?  Caveat: I'm of the school that lambda isn't very
beautiful itself, not in Python.

More information about the Python-ideas mailing list