mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 03:41:32 +00:00
Implement lazy_factory ✨🍰✨
This commit is contained in:
parent
031400c0c4
commit
1d969f0967
@ -1,7 +1,7 @@
|
|||||||
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
||||||
# All Rights Reserved. See LICENSE file for details.
|
# All Rights Reserved. See LICENSE file for details.
|
||||||
|
|
||||||
from functools import update_wrapper
|
from functools import update_wrapper, wraps
|
||||||
|
|
||||||
|
|
||||||
class lazy_property:
|
class lazy_property:
|
||||||
@ -19,3 +19,12 @@ class lazy_property:
|
|||||||
value = self.func(instance)
|
value = self.func(instance)
|
||||||
setattr(instance, self.func.__name__, value)
|
setattr(instance, self.func.__name__, value)
|
||||||
return 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()
|
||||||
|
Loading…
Reference in New Issue
Block a user