From 1d969f0967ca639ba7d66cae83326da1a850cdaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 9 Oct 2018 11:25:11 +0200 Subject: [PATCH] =?UTF-8?q?Implement=20lazy=5Ffactory=20=E2=9C=A8?= =?UTF-8?q?=F0=9F=8D=B0=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tfw/decorators/lazy_property.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tfw/decorators/lazy_property.py b/lib/tfw/decorators/lazy_property.py index c7e00c6..14ad788 100644 --- a/lib/tfw/decorators/lazy_property.py +++ b/lib/tfw/decorators/lazy_property.py @@ -1,7 +1,7 @@ # Copyright (C) 2018 Avatao.com Innovative Learning Kft. # All Rights Reserved. See LICENSE file for details. -from functools import update_wrapper +from functools import update_wrapper, wraps class lazy_property: @@ -19,3 +19,12 @@ class lazy_property: value = self.func(instance) setattr(instance, self.func.__name__, value) return value + + +def lazy_factory(fun): + class wrapper: + @wraps(fun) + @lazy_property + def instance(self): # pylint: disable=no-self-use + return fun() + return wrapper()