functools's partial and update_wrapper does not work together

piotr.findeisen at gmail.com piotr.findeisen at gmail.com
Thu Aug 21 08:09:32 EDT 2008


Hello!

I wanted to use a decorator to wrap partially applied function like
this:
from functools import *

def never_throw(f):
    @wraps(f)
    def wrapper(*args, **kwargs):
        try: return f(*args, **kwargs)
        except: pass
    return wrapper

def foo(i):
    raise ValueError(str(i) + " is too little")

never_throw(partial(foo, 3))

However this fails with an exception saying
AttributeError: 'functools.partial' object has no attribute
'__module__'.

How can I use generic wrapper (never_throw) around partials?

Thank you,
Piotr



More information about the Python-list mailing list