python-benedict/benedict/core/move.py

13 lines
345 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
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(
2020-09-10 17:06:43 +00:00
'Invalid key: "{}", key already in target dict '
2021-10-12 12:27:35 +00:00
'and `overwrite` is disabled.'.format(key_dest)
)
d[key_dest] = d.pop(key_src)