FreeOpcUa / opcua-asyncio

OPC UA library for python >= 3.7
GNU Lesser General Public License v3.0
1.05k stars 347 forks source link

Add `@functools.wraps(func)` to the `wrapper` function of `@uamethod` #1677

Closed FMeinicke closed 2 weeks ago

FMeinicke commented 2 weeks ago

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=}")