Shoddy Decorators (or - Pain, Tears & Decorators)

As an alternative you could use the functools wraps module which will preserve the __name__ of a wrapped function

from functools import wraps 

def my_decorator(f):
  @wraps(f)   # this will preserve the __name__ of the function when it's wrapped
  def wrapper():
    return 2 * f()
  
  return wrapper

@anvil.server.callable     # no need to manually set the name with functools wrap implemented
@my_decorator
def my_func():
  return 42

5 Likes