Skip to content

autora.utils.dictionary

LazyDict

Bases: Mapping

Inspired by https://gist.github.com/gyli/9b50bb8537069b4e154fec41a4b5995a

Source code in autora/utils/dictionary.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class LazyDict(Mapping):
    """Inspired by https://gist.github.com/gyli/9b50bb8537069b4e154fec41a4b5995a"""

    def __init__(self, *args, **kw):
        self._raw_dict = dict(*args, **kw)

    def __getitem__(self, key):
        func = self._raw_dict.__getitem__(key)
        return func()

    def __iter__(self):
        return iter(self._raw_dict)

    def __len__(self):
        return len(self._raw_dict)