Welcome, guest | Sign In | My Account | Store | Cart

A general decorator aimed to decorate decorators, letting them keep (some of) the original attributes of the functions they decorate.

Python, 12 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def decorator(decorating_func):
  """ takes a decorator and fixes it a bit. """
  def new_decorator(func):
    decorated_func = decorating_func(func)
    decorated_func.__name__ = func.__name__
    decorated_func.__doc__ = func.__doc__
    decorated_func.__dict__.update(func.__dict__)
    return decorated_func
  new_decorator.__name__ = decorating_func.__name__
  new_decorator.__doc__ = decorating_func.__doc__
  new_decorator.__dict__.update(decorating_func.__dict__)
  return new_decorator
Created by Hans Zauber on Tue, 13 Nov 2012 (MIT)
Python recipes (4591)
Hans Zauber's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks