python-benedict/benedict/core/move.py

9 lines
296 B
Python
Raw Normal View History

def move(d, key_src, key_dest, overwrite=True):
if key_dest == key_src:
return
if key_dest in d and not overwrite:
2020-09-07 17:25:34 +00:00
raise KeyError(
f"Invalid key: '{key_dest}', key already in target dict and 'overwrite' is disabled."
2021-10-12 12:27:35 +00:00
)
d[key_dest] = d.pop(key_src)