This way we can decorate a function which is already decorated with @uamethod again and things like func.__name__ will correctly return the name of the decorated function and not wrapper.
E.g., the following will now correctly print Calling my_method .... Without @wraps(func) it would have printed Calling wrapper ...:
from functools import wraps
def my_decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
print(f"Calling {func.__name__} with {args=} and {kwargs=}")
@my_decorator
@uamethod
def my_method(parent, arg1, arg2):
print(f"my_method called with {arg1=} and {arg2=}")
This way we can decorate a function which is already decorated with
@uamethod
again and things likefunc.__name__
will correctly return the name of the decorated function and notwrapper
.E.g., the following will now correctly print
Calling my_method ...
. Without@wraps(func)
it would have printedCalling wrapper ...
: