/filesnake/helpers/experiments.py

https://bitbucket.org/gabriele/filesnake
Python | 25 lines | 17 code | 5 blank | 3 comment | 1 complexity | ac923065ce7da1852eeeea46a2bbe0d2 MD5 | raw file
  1. from decorator import decorator
  2. @decorator
  3. def extends(f, self , *a, **kw):
  4. '''
  5. This decorator automatically calls the method of the superclass
  6. '''
  7. fname = f.__name__
  8. getattr(super(type(self),self),fname)(*a,**kw)
  9. return f(self,*a,**kw)
  10. def test():
  11. class B(object):
  12. def __init__(self, hello):
  13. print "hello from b"
  14. class A(B):
  15. @extends
  16. def __init__(self, hello):
  17. print "Hello"
  18. A("Hello")
  19. if __name__ == '__main__':
  20. test()