toumorokoshi/deepmerge

Input base will be mutated

Closed this issue · 3 comments

Thanks for this package so far. :)
Not a bug, more an arguable point: The input will be mutated. I think this should be explicitly indicated in the docs. It's easy to go around with

from copy import deepcopy
from deepmerge import always_merger

base = {"foo": ["bar"]}
next = {"foo": ["baz"]}

# default: mutating
result = always_merger.merge(base, next)
print(base)
# {'foo': ['bar', 'baz']}

# non mutating
base = {"foo": ["bar"]}
result = always_merger.merge(deepcopy(base), next)

print(base)
# {'foo': ['bar']}

Hi @kaotika! I think it's a great point. I attempted to address that, but I realized that the documentation is scattered across the Readme and the readthedocs page.

I've updated everything to hopefully make things a little easier to follow. The fact that the merges are destructive are called out explicitly as part of the new user guide:

https://deepmerge.readthedocs.io/en/latest/guide.html#merges-are-destructive

Which is linked in the readme. What do you think of that?

Hi @toumorokoshi, I think this is the right way to go. Thanks for the quick apply.

closing as resolved. Thanks for the feedback!