Created
June 13, 2017 21:26
-
-
Save thomasleese/ee78c2dc3885d7aba170b3ee881dd8ca to your computer and use it in GitHub Desktop.
Tracking
This file contains hidden or 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
| def wrap_function(function): | |
| def wrapper(*args, **kwargs): | |
| print("name", function.__name__) | |
| print("args", args) | |
| print("kwargs", kwargs) | |
| return function(*args, **kwargs) | |
| return wrapper | |
| def wrap_class(cls): | |
| ignored_methods = [ | |
| '__dict__', | |
| '__class__', | |
| '__repr__', # this has to be ignored otherwise the 'print' in wrapper keeps calling 'repr' recurisvely | |
| '__new__', # gotta figure out why this needs to be ignored, dunno why it needs to be | |
| ] | |
| for name in [x for x in dir(cls) if x not in ignored_methods]: | |
| method = getattr(cls, name) | |
| print(name) | |
| setattr(cls, name, wrap_function(method)) | |
| return cls | |
| @wrap_class | |
| class Test: | |
| def __init__(self, a): | |
| self.a = a | |
| t = Test(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment