I'm trying to decorate a function but I want the decorated version of the function to "look" like the original function. Trivial example:
def decorator(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
wrapper.__name__ = func.__name__
wrapper.__str__ = lambda x: str(func)
wrapper.__repr__ = lambda x: repr(func)
return wrapper
But when I do something like str(wrapped_function)
I get something uninformative like <function decorator.<locals>.wrapper at 0x10323e048>
.
How can I edit this so that it returns the correct repr
and str
?
Not a duplicate of this question as (although the solution is the same), the question is useful and different.