Path: blob/main/test/lib/python3.9/site-packages/setuptools/_distutils/_collections.py
4799 views
import collections1import itertools234# from jaraco.collections 3.5.15class DictStack(list, collections.abc.Mapping):6"""7A stack of dictionaries that behaves as a view on those dictionaries,8giving preference to the last.910>>> stack = DictStack([dict(a=1, c=2), dict(b=2, a=2)])11>>> stack['a']12213>>> stack['b']14215>>> stack['c']16217>>> len(stack)18319>>> stack.push(dict(a=3))20>>> stack['a']21322>>> set(stack.keys()) == set(['a', 'b', 'c'])23True24>>> set(stack.items()) == set([('a', 3), ('b', 2), ('c', 2)])25True26>>> dict(**stack) == dict(stack) == dict(a=3, c=2, b=2)27True28>>> d = stack.pop()29>>> stack['a']30231>>> d = stack.pop()32>>> stack['a']33134>>> stack.get('b', None)35>>> 'c' in stack36True37"""3839def __iter__(self):40dicts = list.__iter__(self)41return iter(set(itertools.chain.from_iterable(c.keys() for c in dicts)))4243def __getitem__(self, key):44for scope in reversed(tuple(list.__iter__(self))):45if key in scope:46return scope[key]47raise KeyError(key)4849push = list.append5051def __contains__(self, other):52return collections.abc.Mapping.__contains__(self, other)5354def __len__(self):55return len(list(iter(self)))565758