Created
October 24, 2012 16:40
-
-
Save matthewryanscott/3947224 to your computer and use it in GitHub Desktop.
Use of functools.partial instead of using a closure
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
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