pikachewie.utils – Utilities used internally by PikaChewie¶
-
class
pikachewie.utils.
cached_property
(func, name=None, doc=None)¶ A decorator that converts a function into a lazy property.
The function wrapped is called the first time to retrieve the result and then that calculated result is used the next time you access the value:
class Foo(object): @cached_property def foo(self): # calculate something important here return 42
The class has to have a __dict__ in order for this property to work.
Cloned from werkzeug.utils.cached_property.
ref: https://github.com/mitsuhiko/werkzeug/blob/master/LICENSE
-
pikachewie.utils.
delegate
(obj, attr)¶ Define an instance property that is delegated to self.<obj>.<attr>.
Example:
>>> class MyClass(object): ... ... def __init__(self, obj): ... self.obj = obj ... ... foo = delegate('obj', 'count') ... >>> a = MyClass(obj=list()) >>> a.foo <built-in method count of list object at 0x104ad15f0> >>> a.obj.count <built-in method count of list object at 0x104ad15f0>