Created
January 12, 2018 11:17
-
-
Save jbasko/4736cac264168fb292e2744d4722cbc5 to your computer and use it in GitHub Desktop.
universal decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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