Navigation

Source code for pyramid.decorator

[docs]classreify(object):""" Use as a class method decorator. It operates almost exactly like the Python ``@property`` decorator, but it puts the result of the method it decorates into the instance dict after the first call, effectively replacing the function it decorates with an instance variable. It is, in Python parlance, a non-data descriptor. An example: .. code-block:: python class Foo(object): @reify def jammy(self): print('jammy called') return 1 And usage of Foo: >>> f = Foo() >>> v = f.jammy 'jammy called' >>> print(v) 1 >>> f.jammy 1 >>> # jammy func not called the second time; it replaced itself with 1 """def__init__(self,wrapped):self.wrapped=wrappedtry:self.__doc__=wrapped.__doc__except:# pragma: no coverpassdef__get__(self,inst,objtype=None):ifinstisNone:returnselfval=self.wrapped(inst)setattr(inst,self.wrapped.__name__,val)returnval