From 6167a8ccf23ead3cc456f4d1aba3ed021e8e7caf Mon Sep 17 00:00:00 2001 From: Paul Healy Date: Tue, 11 Apr 2017 22:32:22 +0100 Subject: [PATCH] merge file objects using references (not copy.copy) --- invoke/config.py | 4 ++++ sites/www/changelog.rst | 1 + tests/merge_dicts.py | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/invoke/config.py b/invoke/config.py index b3531d20e..fc7826a03 100644 --- a/invoke/config.py +++ b/invoke/config.py @@ -995,6 +995,8 @@ def merge_dicts(base, updates): else: if isinstance(base[key], dict): raise _merge_error(base[key], value) + elif isinstance(value, file): + base[key] = value else: base[key] = copy.copy(value) # New values get set anew @@ -1003,6 +1005,8 @@ def merge_dicts(base, updates): # updates dict, which can lead to nasty state-bleed bugs otherwise if isinstance(value, dict): base[key] = copy_dict(value) + elif isinstance(value, file): + base[key] = value # Non-dict values just get set straight else: base[key] = copy.copy(value) diff --git a/sites/www/changelog.rst b/sites/www/changelog.rst index cdb393841..32cbd4349 100644 --- a/sites/www/changelog.rst +++ b/sites/www/changelog.rst @@ -2,6 +2,7 @@ Changelog ========= +* :support:`-` Merge file objects in config object by reference. * :support:`-` Fixed some Python 2.6 incompatible string formatting that snuck in recently. * :feature:`-` Switched the order of the first two arguments of diff --git a/tests/merge_dicts.py b/tests/merge_dicts.py index fc22254d8..4018bec52 100644 --- a/tests/merge_dicts.py +++ b/tests/merge_dicts.py @@ -85,6 +85,11 @@ def dict_value_merges_are_not_references(self): # BUT that 'proj' remains UNTOUCHED eq_(proj['foo']['bar']['biz'], 'proj value') + def merge_file_types_by_reference(self): + d1 = {} + d2 = {'foo': open(__file__)} + merge_dicts(d1, d2) + eq_(d1['foo'].closed, False) class copy_dict_(Spec): def returns_deep_copy_of_given_dict(self):