Skip to content

Commit 7513d4f

Browse files
committed
Correct len and iter operators for LazyDict
1 parent 27c55d5 commit 7513d4f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tools/toolchains/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from types import ListType
2424
from shutil import copyfile
2525
from os.path import join, splitext, exists, relpath, dirname, basename, split, abspath, isfile, isdir, normcase
26+
from itertools import chain
2627
from inspect import getmro
2728
from copy import deepcopy
2829
from tools.config import Config
@@ -48,6 +49,8 @@ def __init__(self):
4849
self.lazy = {}
4950

5051
def add_lazy(self, key, thunk):
52+
if key in self.eager:
53+
del self.eager[key]
5154
self.lazy[key] = thunk
5255

5356
def __getitem__(self, key):
@@ -63,6 +66,12 @@ def __setitem__(self, key, value):
6366
def __contains__(self, key):
6467
return key in self.eager or key in self.lazy
6568

69+
def __iter__(self):
70+
return chain(iter(self.eager), iter(self.lazy))
71+
72+
def __len__(self):
73+
return len(self.eager) + len(self.lazy)
74+
6675
def update(self, other):
6776
if isinstance(other, LazyDict):
6877
self.eager.update(other.eager)

0 commit comments

Comments
 (0)