mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-09-19 02:54:09 +00:00
20 lines
574 B
Python
20 lines
574 B
Python
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
|
|
class LazyInitialise:
|
|
"""
|
|
Decorator that replaces a function with the value
|
|
it calculates on the first call.
|
|
"""
|
|
def __init__(self, func):
|
|
self.func = func
|
|
self.__doc__ = func.__doc__
|
|
|
|
def __get__(self, instance, owner):
|
|
if instance is None:
|
|
return self # avoids potential __new__ TypeError
|
|
value = self.func(instance)
|
|
setattr(instance, self.func.__name__, value)
|
|
return value
|