fix DefaultDict.__or__
This commit is contained in:
@@ -10,3 +10,6 @@ class DictDefault(Dict):
|
|||||||
|
|
||||||
def __missing__(self, key):
|
def __missing__(self, key):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def __or__(self, other):
|
||||||
|
return DictDefault(super().__or__(other))
|
||||||
|
|||||||
@@ -72,6 +72,13 @@ class DictDefaultTest(unittest.TestCase):
|
|||||||
|
|
||||||
assert cfg.random_key is None, "DictDefault should return None for missing keys"
|
assert cfg.random_key is None, "DictDefault should return None for missing keys"
|
||||||
|
|
||||||
|
def test_dict_or(self):
|
||||||
|
cfg = DictDefault({}) | DictDefault({})
|
||||||
|
|
||||||
|
assert (
|
||||||
|
cfg.random_key is None
|
||||||
|
), "DictDefault should return None for missing keys after | operation"
|
||||||
|
|
||||||
def test_dict_nested_missingparentkey(self):
|
def test_dict_nested_missingparentkey(self):
|
||||||
"""
|
"""
|
||||||
Due to subclassing Dict, DictDefault will error if we try to access a nested key whose parent key does not exist.
|
Due to subclassing Dict, DictDefault will error if we try to access a nested key whose parent key does not exist.
|
||||||
|
|||||||
Reference in New Issue
Block a user