Decorator is a part of Dooku that contains various useful decorators that could be helpful in daily usage basis. The module is very small now, so please feel free to contribute and share your experience with others.


class dooku.decorator.cached_property(func)

Decorator that converts a method into a lazy property.

The wrapped method is called the first time to retrieve the result and then the calculated result is used next time you access the value:

class Holocron(object):

    def jinja_env(self):
        # (create and configure jinja environment)
        return jinja_env

Implementation details

The property is implemented as non-data descriptor. That mean, the descriptor is invoked if there’s no entry with the same name in the instance’s __dict__.

This trick helps us to get rid of the function call overhead.

Parameters:func – A method to be wrapped.