Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge file objects using references (not copy.copy) #437

Merged
merged 1 commit into from Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions invoke/config.py
Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions sites/www/changelog.rst
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/merge_dicts.py
Expand Up @@ -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):
Expand Down