[Python-Dev] The decorator module

Michele Simionato michele.simionato at gmail.com
Mon May 9 07:08:54 CEST 2005


On 5/6/05, Phillip J. Eby <pje at telecommunity.com> wrote:
> In this case, the informally-discussed proposal is to add a mutable
> __signature__ to functions, and have it be used by inspect.getargspec(), so
> that decorators can copy __signature__ from the decoratee to the decorated
> function.

Is there in the plans any facility to copy functions? Currently I am doing

def copyfunc(func):
    "Creates an independent copy of a function."
    c = func.func_code
    nc = new.code(c.co_argcount, c.co_nlocals, c.co_stacksize, c.co_flags,
                  c.co_code, c.co_consts, c.co_names, c.co_varnames,
                  c.co_filename, c.co_name, c.co_firstlineno,
                  c.co_lnotab, c.co_freevars, c.co_cellvars)
    return new.function(nc, func.func_globals, func.func_name,
                        func.func_defaults, func.func_closure)
 
and I *hate* it!

I have updated my module to version 0.2, with an improved discussion
of decorators in multithreaded programming ("locked", "threaded",
"deferred"): http://www.phyast.pitt.edu/~micheles/python/decorator.zip


        Michele Simionato


More information about the Python-Dev mailing list