Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/importlib_metadata/_collections.py: 100%
10 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1import collections
4# from jaraco.collections 3.3
5class FreezableDefaultDict(collections.defaultdict):
6 """
7 Often it is desirable to prevent the mutation of
8 a default dict after its initial construction, such
9 as to prevent mutation during iteration.
11 >>> dd = FreezableDefaultDict(list)
12 >>> dd[0].append('1')
13 >>> dd.freeze()
14 >>> dd[1]
15 []
16 >>> len(dd)
17 1
18 """
20 def __missing__(self, key):
21 return getattr(self, '_frozen', super().__missing__)(key)
23 def freeze(self):
24 self._frozen = lambda key: self.default_factory()
27class Pair(collections.namedtuple('Pair', 'name value')):
28 @classmethod
29 def parse(cls, text):
30 return cls(*map(str.strip, text.split("=", 1)))