nested_set raises KeyError if not create_missing

This commit is contained in:
Profitroll 2023-08-06 12:43:01 +02:00
parent 783443e448
commit 3273b86b75
Signed by: profitroll
GPG Key ID: FA35CAB49DACD3B2

View File

@ -55,7 +55,9 @@ def nested_set(target: dict, value: Any, *path: str, create_missing=True) -> dic
elif create_missing:
d = d.setdefault(key, {})
else:
return target
raise KeyError(
f"Key '{key}' is not found under path provided ({path}) and create_missing is False"
)
if path[-1] in d or create_missing:
d[path[-1]] = value
return target