Skip to content
Snippets Groups Projects
Commit 8d3c9c76 authored by Izzard, Robert Dr (Maths & Physics)'s avatar Izzard, Robert Dr (Maths & Physics)
Browse files

update so None is overwritten in merge_dicts if the other value is non-None

parent 2c402f90
No related branches found
No related tags found
No related merge requests found
......@@ -510,6 +510,21 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict:
):
new_dict[key] = merge_dicts(dict_1[key], dict_2[key])
# one key is None, just use the other
elif dict_1[key] is None:
try:
new_dict[key] = dict_2[key]
except:
msg = f"{key}: Failed to set from {dict_2[key]} when other key was of NoneType "
raise ValueError(msg) from e
elif dict_1[key] is None:
try:
new_dict[key] = dict_1[key]
except:
msg = f"{key}: Failed to set from {dict_1[key]} when other key was of NoneType "
raise ValueError(msg) from e
# string-int clash : convert both to ints and save
elif (
isinstance(dict_1[key], str)
......@@ -525,6 +540,7 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict:
)
raise ValueError(msg) from e
# string-float clash : convert both to floats and save
elif (
isinstance(dict_1[key], str)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment