fix DefaultDict.__or__
Browse files- src/axolotl/utils/dict.py +3 -0
- tests/test_dict.py +7 -0
src/axolotl/utils/dict.py
CHANGED
@@ -10,3 +10,6 @@ class DictDefault(Dict):
|
|
10 |
|
11 |
def __missing__(self, key):
|
12 |
return None
|
|
|
|
|
|
|
|
10 |
|
11 |
def __missing__(self, key):
|
12 |
return None
|
13 |
+
|
14 |
+
def __or__(self, other):
|
15 |
+
return DictDefault(super().__or__(other))
|
tests/test_dict.py
CHANGED
@@ -72,6 +72,13 @@ class DictDefaultTest(unittest.TestCase):
|
|
72 |
|
73 |
assert cfg.random_key is None, "DictDefault should return None for missing keys"
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
def test_dict_nested_missingparentkey(self):
|
76 |
"""
|
77 |
Due to subclassing Dict, DictDefault will error if we try to access a nested key whose parent key does not exist.
|
|
|
72 |
|
73 |
assert cfg.random_key is None, "DictDefault should return None for missing keys"
|
74 |
|
75 |
+
def test_dict_or(self):
|
76 |
+
cfg = DictDefault({}) | DictDefault({})
|
77 |
+
|
78 |
+
assert (
|
79 |
+
cfg.random_key is None
|
80 |
+
), "DictDefault should return None for missing keys after | operation"
|
81 |
+
|
82 |
def test_dict_nested_missingparentkey(self):
|
83 |
"""
|
84 |
Due to subclassing Dict, DictDefault will error if we try to access a nested key whose parent key does not exist.
|