Skip to content

Instantly share code, notes, and snippets.

@thomasleese
Created June 13, 2017 21:26
Show Gist options
  • Select an option

  • Save thomasleese/ee78c2dc3885d7aba170b3ee881dd8ca to your computer and use it in GitHub Desktop.

Select an option

Save thomasleese/ee78c2dc3885d7aba170b3ee881dd8ca to your computer and use it in GitHub Desktop.
Tracking
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