Add a "merge" option for box_merge_lists (#263) - #323
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
merge_update can already combine lists with extend and unique, but there was no way to merge lists of dictionaries the way nested dicts merge. Add a "merge" option that walks both lists by index, recursing into dicts at the same position so their keys combine and appending any extra incoming items. Closes cdgriffith#263.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a "merge" value for the existing box_merge_lists keyword so merge_update can combine lists of dictionaries element by element instead of replacing the whole list, which is what #263 asked for.
Right now box_merge_lists handles the two list-level strategies, extend and unique, but nested dictionaries buried inside a list still get dropped on merge. With this option merge_update walks both lists by index: when the same position holds a dict on each side it recurses (reusing merge_update so it keeps working at any depth), otherwise the incoming value wins, and any extra incoming elements are appended. The default behavior is unchanged since this only kicks in when you explicitly pass box_merge_lists="merge".
Using the example from the issue:
I added a docstring to merge_update covering all the list modes, tests for the happy and sad paths, and CHANGES/AUTHORS entries.