Call for signatories for J2

Michael Sparks michaels at rd.bbc.co.uk
Thu Aug 26 17:25:23 CEST 2004


Anthony Baxter wrote:

> On Thu, 26 Aug 2004 14:44:27 +0100, Michael Sparks
> <michaels at rd.bbc.co.uk> wrote:
>> Using proposed J2: (tested)
>> class Foo:
>>    using:
>>       staticmethod
>>       eval("(memoise,esiomem)[x==0]")
>>    def Hoo(Who, *args):
>>       print "Yoo", Who
> 
> Why wouldn't you instead write this as:
...
[alternative using an if statement before]
...
> Don't use eval unless it's absolutely necessary, _please_.

The question was asking about using a conditional expression in the
decorator list. Since the closest equivalent as an expression that
evaluates to a function is something like (memoise,esiomem)[x==0] and
since you can only put function calls there, that was why I put eval
there.

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.

Regards,


Michael.
-- 
Michael.Sparks at rd.bbc.co.uk    
British Broadcasting Corporation, Research and Development
Kingswood Warren, Surrey KT20 6NP

This message (and any attachments) may contain personal views
which are not the views of the BBC unless specifically stated.




More information about the Python-list mailing list