From a241842ef941ebf9e921d661ecf46e06c32b7b2a Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Wed, 31 Dec 2014 13:40:16 +0100 Subject: [PATCH] Better dict merging (less side-effectful) --- tests/integration/manifests/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/integration/manifests/__init__.py b/tests/integration/manifests/__init__.py index 615e3e5..d6afbd6 100644 --- a/tests/integration/manifests/__init__.py +++ b/tests/integration/manifests/__init__.py @@ -32,15 +32,11 @@ def merge_dicts(*args): def clone(obj): copy = obj if isinstance(obj, dict): - copy = {} - for key, value in obj.iteritems(): - copy[key] = clone(value) + copy = {key: clone(value) for key, value in obj.iteritems()} if isinstance(obj, list): - copy = [] - copy.extend(obj) + copy = [clone(value) for value in obj] if isinstance(obj, set): - copy = set() - copy.update(obj) + copy = set([clone(value) for value in obj]) return copy def merge(a, b, path=[]):