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(
2022-02-13 10:35:43 +00:00
"Invalid key: '{}', key already in target dict "
"and `overwrite` is disabled.".format(key_dest)
2021-10-12 12:27:35 +00:00
)
d[key_dest] = d.pop(key_src)