Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/openpyxl/utils/bound_dictionary.py: 43%

10 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1# Copyright (c) 2010-2022 openpyxl 

2 

3from collections import defaultdict 

4 

5 

6class BoundDictionary(defaultdict): 

7 """ 

8 A default dictionary where elements are tightly coupled. 

9 

10 The factory method is responsible for binding the parent object to the child. 

11 

12 If a reference attribute is assigned then child objects will have the key assigned to this. 

13 

14 Otherwise it's just a defaultdict. 

15 """ 

16 

17 def __init__(self, reference=None, *args, **kw): 

18 self.reference = reference 

19 super(BoundDictionary, self).__init__(*args, **kw) 

20 

21 

22 def __getitem__(self, key): 

23 value = super(BoundDictionary, self).__getitem__(key) 

24 if self.reference is not None: 

25 setattr(value, self.reference, key) 

26 return value