Skip to content

Instantly share code, notes, and snippets.

@jbasko
Created January 12, 2018 11:17
Show Gist options
  • Save jbasko/4736cac264168fb292e2744d4722cbc5 to your computer and use it in GitHub Desktop.
Save jbasko/4736cac264168fb292e2744d4722cbc5 to your computer and use it in GitHub Desktop.
universal decorator
class universal_decorator:
wrappers = []
def __init__(self, method):
self.original_method = method
self.method = self.original_method
self.apply_decorators()
def apply_decorators(self):
for wrapper in self.wrappers:
self.method = wrapper(self.method)
def __get__(self, instance, owner):
if instance is None:
return self.method
else:
return self.method.__get__(instance, owner)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment