From 8ded14c3d8d8e1cc0468086b88d16d2b6caf4804 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 12 Jul 2014 12:03:08 +0400 Subject: [PATCH] Add mergedicts_copy: non-modifying mergedicts --- powerline/lib/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/powerline/lib/__init__.py b/powerline/lib/__init__.py index b9839afc..252b1e2e 100644 --- a/powerline/lib/__init__.py +++ b/powerline/lib/__init__.py @@ -26,6 +26,21 @@ def mergedicts(d1, d2): d1[k] = d2[k] +def mergedicts_copy(d1, d2): + '''Recursively merge two dictionaries. + + Dictionaries are not modified. Copying happens only if necessary. Assumes + that first dictionary support .copy() method. + ''' + ret = d1.copy() + for k in d2: + if k in d1 and isinstance(d1[k], dict) and isinstance(d2[k], dict): + ret[k] = mergedicts_copy(d1[k], d2[k]) + else: + ret[k] = d2[k] + return ret + + def add_divider_highlight_group(highlight_group): def dec(func): @wraps_saveargs(func)