Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/openpyxl/utils/bound_dictionary.py: 100%
10 statements
« prev ^ index » next coverage.py v7.3.3, created at 2023-12-20 06:34 +0000
« prev ^ index » next coverage.py v7.3.3, created at 2023-12-20 06:34 +0000
1# Copyright (c) 2010-2023 openpyxl
3from collections import defaultdict
6class BoundDictionary(defaultdict):
7 """
8 A default dictionary where elements are tightly coupled.
10 The factory method is responsible for binding the parent object to the child.
12 If a reference attribute is assigned then child objects will have the key assigned to this.
14 Otherwise it's just a defaultdict.
15 """
17 def __init__(self, reference=None, *args, **kw):
18 self.reference = reference
19 super(BoundDictionary, self).__init__(*args, **kw)
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