Call for signatories for J2
Paul McGuire
ptmcg at austin.rr._bogus_.com
Thu Aug 26 12:24:39 EDT 2004
"Michael Sparks" <michaels at rd.bbc.co.uk> wrote in message
news:cgkvtr$5l1$1 at nntp0.reith.bbc.co.uk...
> Anthony Baxter wrote:
>
>
> I suppose instead I could've had:
>
> def identity(actualFunc):
> def decorate(func):
> return actualFunc(func)
> return decorate
>
> class Foo:
> @staticmethod
> @identity((memoise,esiomem)[x==1])
> def Hoo(Who, *args):
> print "Yoo", Who
>
> Which is nicer, but still pretty hideous. I'd agree that the preceding
> if statement approach is better than a conditional expression.
>
On the contrary, I think it likely that, in the event a module of standard
decorators is eventually provided (I thought I heard something like this in
some prior thread, perhaps on python-dev), that there will need to be some
flavors of nullDecorator such as unchanged and disabled below (I think I
have the decorator syntax down, if not I hope you get the idea):
def unchanged(func):
"This decorator doesn't add any behavior"
return func
def disabled(func):
"This decorator disables the provided function, and does nothing"
def emptyFunc(*args,**kargs):
pass
return emptyFunc
# define this as equivalent to unchanged, for nice symmetry with disabled
enabled = unchanged
Now you could do something like:
globalEnableFlag = True
@( (disabled,enabled)[globalEnableFlag ] )
def specialFunctionFoo()
pass
or
using:
(disabled,enabled)[globalEnableFlag ]
def specialFunctionFoo()
pass
-- Paul
More information about the Python-list
mailing list