mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 06:22:55 +00:00 
			
		
		
		
	Implement lazy_factory ✨🍰✨
This commit is contained in:
		@@ -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()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user