File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change 22import itertools
33
44
5- # from jaraco.collections 3.5
5+ # from jaraco.collections 3.5.1
66class DictStack (list , collections .abc .Mapping ):
77 """
88 A stack of dictionaries that behaves as a view on those dictionaries,
@@ -15,6 +15,8 @@ class DictStack(list, collections.abc.Mapping):
1515 2
1616 >>> stack['c']
1717 2
18+ >>> len(stack)
19+ 3
1820 >>> stack.push(dict(a=3))
1921 >>> stack['a']
2022 3
@@ -40,7 +42,7 @@ def __iter__(self):
4042 return iter (set (itertools .chain .from_iterable (c .keys () for c in dicts )))
4143
4244 def __getitem__ (self , key ):
43- for scope in reversed (self ):
45+ for scope in reversed (tuple ( list . __iter__ ( self )) ):
4446 if key in scope :
4547 return scope [key ]
4648 raise KeyError (key )
@@ -49,3 +51,6 @@ def __getitem__(self, key):
4951
5052 def __contains__ (self , other ):
5153 return collections .abc .Mapping .__contains__ (self , other )
54+
55+ def __len__ (self ):
56+ return len (list (iter (self )))
You can’t perform that action at this time.
0 commit comments