Skip to content

Instantly share code, notes, and snippets.

@matthewryanscott
Created October 24, 2012 16:40
Show Gist options
  • Save matthewryanscott/3947224 to your computer and use it in GitHub Desktop.
Save matthewryanscott/3947224 to your computer and use it in GitHub Desktop.
Use of functools.partial instead of using a closure
from functools import partial
def tracecalls(cls):
def my__getattribute__(self, name):
attr = super(cls, self).__getattribute__(name)
return attr if not callable(attr) else partial(whencalled, attr)
cls.__getattribute__ = my__getattribute__
return cls
def whencalled(func, *args, **kw):
rc = func(*args, **kw)
logtrace(func, args, kw, rc)
return rc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment