[PEAK] dispatch -- chaining decorators

Ian Bicking ianb at colorstudy.com
Fri Dec 9 17:38:15 EST 2005


Simon Belak wrote:
> Ian Bicking wrote:
>  >
>  > I wonder if this decorator library would help:
>  > http://www.phyast.pitt.edu/~micheles/python/documentation.html
>  >
>  > It's supposed to maintain function signatures.
>  >
> 
> decorator is a bit limiting as it is my understanding that it can only 
> be applied to functions with signature _(f, *args, **kw).

That's not particularly problematic.  For example:

def unpickle(arg_name):
     def __entangle(func, *args, **kwargs):
         pickle_pos = list(func.func_code.co_varnames).index(arg_name)
         assert pickle_pos < func.func_code.co_argcount
         return func(*args[:pickle_pos] + (load(args[pickle_pos]),)
                     + args[pickle_pos+1:], **kwargs)
     return decorator(__entangle)

-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org



More information about the PEAK mailing list