Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/importlib_metadata/_collections.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

13 statements  

1import collections 

2import typing 

3 

4 

5# from jaraco.collections 3.3 

6class FreezableDefaultDict(collections.defaultdict): 

7 """ 

8 Often it is desirable to prevent the mutation of 

9 a default dict after its initial construction, such 

10 as to prevent mutation during iteration. 

11 

12 >>> dd = FreezableDefaultDict(list) 

13 >>> dd[0].append('1') 

14 >>> dd.freeze() 

15 >>> dd[1] 

16 [] 

17 >>> len(dd) 

18 1 

19 """ 

20 

21 def __missing__(self, key): 

22 return getattr(self, '_frozen', super().__missing__)(key) 

23 

24 def freeze(self): 

25 self._frozen = lambda key: self.default_factory() 

26 

27 

28class Pair(typing.NamedTuple): 

29 name: str 

30 value: str 

31 

32 @classmethod 

33 def parse(cls, text): 

34 return cls(*map(str.strip, text.split("=", 1)))