Skip to content

Instantly share code, notes, and snippets.

@inirudebwoy
Created March 22, 2017 20:40
Show Gist options
  • Save inirudebwoy/10d66d31c5c663942a3e826bef821504 to your computer and use it in GitHub Desktop.
Save inirudebwoy/10d66d31c5c663942a3e826bef821504 to your computer and use it in GitHub Desktop.
Metaclass wrapping each function call with an argument printer
from functools import wraps
def printer(f):
@wraps(f)
def wrapper(*args, **kwargs):
print(args)
return f(*args, **kwargs)
return wrapper
class MyMeta(type):
def __new__(meta, name, bases, dct):
for k, v in dct.iteritems():
if callable(v):
v = printer(v)
dct[k] = v
return super(MyMeta, meta).__new__(meta, name, bases, dct)
class Foo(object):
__metaclass__ = MyMeta
def double(self, x):
return x * 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment