cp-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub kobejean/cp-library

:warning: cp_library/misc/decorators/lazy_class_attribute_cls.py

Code

import cp_library.misc.decorators.__header__

class lazy_class_attribute:
    def __init__(self, fn):
        self.fn = fn
        self.value = None
    
    def __get__(self, instance, owner):
        if self.value is None:
            # Call with owner (the class) as the first argument
            self.value = self.fn(owner)
        return self.value
'''
╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸
             https://kobejean.github.io/cp-library               
'''

class lazy_class_attribute:
    def __init__(self, fn):
        self.fn = fn
        self.value = None
    
    def __get__(self, instance, owner):
        if self.value is None:
            # Call with owner (the class) as the first argument
            self.value = self.fn(owner)
        return self.value
Back to top page