Skip to content Skip to sidebar Skip to footer

Functools.update_wrapper() Doesn't Work Properly

I use Functools.update_wrapper() in my decorator, but It seems like update_wrapper rewrites only function attributes (such as __doc__, __name__), but does not affect on help() func

Solution 1:

functools.update_wrapper() sets the attribute on the instance, but help() looks at the information on the type.

So printer.__doc__ gives you the instance attribute, help() prints information about type(printer), e.g. the memoized class, which does not have a __doc__ attribute.

This is not a bug, this is all by design; help() will always look at the class when you pass in an instance. Don't use a class as decorator if you want help() to work for the decorated function.

Post a Comment for "Functools.update_wrapper() Doesn't Work Properly"