1 """Lazy dictionaries calculate self content upon first access"""
4 "Abstract parent of all lazy dictionaries"
7 raise NotImplementedError
9 def __getattr__(self, attr):
10 if self.data is None: self._init()
11 return getattr(self.data, attr)
13 def __getitem__(self, key):
14 if self.data is None: self._init()
17 def __setitem__(self, key, value):
18 if self.data is None: self._init()
19 self.data[key] = value
22 class LazyDictInitFunc(LazyDict):
23 "Lazy dict that initializes itself by calling supplied init function"
25 def __init__(self, init=None, *args, **kw):
34 data = {} # just a new empty dict
36 data = init(*self.args, **self.kw)