summaryrefslogtreecommitdiff
path: root/grc/core/utils/descriptors/_lazy.py
blob: 7d5c2c49c03ffd842a921e2fe494fe84526981e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright 2016 Free Software Foundation, Inc.
# This file is part of GNU Radio
#
# SPDX-License-Identifier: GPL-2.0-or-later
#

import functools


class lazy_property(object):

    def __init__(self, func):
        self.func = func
        functools.update_wrapper(self, func)

    def __get__(self, instance, owner):
        if instance is None:
            return self
        value = self.func(instance)
        setattr(instance, self.func.__name__, value)
        return value


def nop_write(prop):
    """Make this a property with a nop setter"""

    def nop(self, value):
        pass
    return prop.setter(nop)