decorator.py 560 B

12345678910111213141516171819
  1. # from Pyramid
  2. class reify(object):
  3. """Put the result of a method which uses this (non-data)
  4. descriptor decorator in the instance dict after the first call,
  5. effectively replacing the decorator with an instance variable.
  6. """
  7. def __init__(self, wrapped):
  8. self.wrapped = wrapped
  9. self.__doc__ = wrapped.__doc__
  10. def __get__(self, inst, objtype=None):
  11. if inst is None:
  12. return self
  13. val = self.wrapped(inst)
  14. setattr(inst, self.wrapped.__name__, val)
  15. return val