Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. import types
  2.  
  3. from functools import wraps
  4.  
  5. def recurse(fn):
  6.  
  7. @wraps(fn)
  8. def wrapper(self):
  9. v = fn(self)
  10.  
  11. @recurse
  12. @wraps(fn)
  13. def replacement(self):
  14. return v + 1
  15.  
  16. setattr(self, fn.__name__, types.MethodType(replacement, self))
  17. return v
  18. return wrapper
  19.  
  20. class Wtf(object):
  21.  
  22. @recurse
  23. def value(self):
  24. return 4
  25.  
  26. x = Wtf()
  27. print x.value()
  28. print x.value()
  29. print x.value()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement