mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-21 21:21: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.
|
||||
# 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()
|
||||
|
Loading…
Reference in New Issue
Block a user