[PEAK] Use cases for the priority feature

P.J. Eby pje at telecommunity.com
Tue Aug 17 19:56:17 EDT 2010

At 12:37 AM 8/18/2010 +0200, Christoph Zwerschke wrote:
>Granted, that should work. But it looks a bit overly complicated to 
>me, because you have to work with functions getters here, whereas 
>with the priority parameter you could use the actual functions and 
>spare some of the overhead.

Here's Yet Another Way To Do It, btw:

def quality(pri):
     def decorate(func):
         def decorated(*args, **kw):
             return pri, lambda: func(*args, **kw)
         return decorated
     return decorate

def call_highest_priority(results):
     for quality, method in sorted(results, key=operator.itemgetter(0)):
         return method()

@combine_using(abstract, call_highest_priority)
def convertImage(...):

@when(convertImage, ...)
def someConversion(...):

In other words, you can actually defer the execution of the methods 
and still get the benefits of selection.

Granted, it still requires some thought to design and set up, and I'm 
not totally convinced as to which, if any of these approaches should 
be recommended as a best practice.  It would help if we could nail 
down the key tradeoffs involved in different combination strategies 
and use cases, so that I could document a set of good recommendations.

(Hm.  I'm also beginning to also think that maybe combine_using 
should not include overridden methods, unless you ask it to.)

More information about the PEAK mailing list