Skip to content

Instantly share code, notes, and snippets.

@kanghyojun
Created November 29, 2013 07:39
Show Gist options
  • Select an option

  • Save kanghyojun/7702636 to your computer and use it in GitHub Desktop.

Select an option

Save kanghyojun/7702636 to your computer and use it in GitHub Desktop.
from functools import wraps
class R(object):
def __init__(self, a):
self.a = a
def post(self, f):
setattr(self.a, 'blah', 'blah')
class A(object):
def reg(self, f):
self.f = f
setattr(self, f.func_name, R(self))
@wraps(f)
def deco(*args, **kwards):
print 'called'
setattr(f, 'a', 'a')
return f(*args, **kwards)
return deco
a = A()
@a.reg
def some_func():
print 'a'
@a.some_func.post
def post_func():
print 'b'
if __name__ == '__main__':
print a.f
print a.some_func
print a.blah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment