Skip to content

Instantly share code, notes, and snippets.

@k0001
Created May 6, 2009 06:31
Show Gist options
  • Save k0001/107392 to your computer and use it in GitHub Desktop.
Save k0001/107392 to your computer and use it in GitHub Desktop.
>>> class A(object):
... @classmethod
... def magic(cls, fn):
... def _f(*args, **kwargs):
... print "Hello from", cls, "_f", args, kwargs
... return fn(*args, **kwargs)
... return _f
...
>>> class B(object):
... @A.magic
... def foo(self, a, b, c):
... return a + b + c
...
>>> b = B()
>>> b.foo(1, 3, c=5)
Hello from <class '__main__.A'> _f (<__main__.B object at 0x17872d0>, 1, 3) {'c': 5}
9
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment