Skip to content

Commit

Permalink
Add docstrings for merge_lists and merge_dicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhearsum committed Oct 2, 2017
1 parent bd9c0ee commit 70e07aa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions auslib/blobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def createBlob(data):


def merge_lists(*lists):
"""Merge an arbitrary number of lists together, keeping only the unique
items, and not worrying about order. This is essentially a hack to treat
lists in blobs as sets. In an ideal world, that's what they'd be, but
because we use jsonschema for validation, we cannot use proper sets."""
result = []
for l in lists:
for i in l:
Expand All @@ -65,6 +69,13 @@ def merge_lists(*lists):


def merge_dicts(ancestor, left, right):
"""Perform a 3-way merge on dictonaries. We used to use an external library
for this, but we replaced it with this because our merge can be a bit more
liberal than the general case. Specifically:
* Lists are treated as sets (see above for details)
* A type mismatch of unicode vs string is OK as long as the text is the same
(Any other type mismatches result in a failure to merge.)
"""
result = {}
dicts = (ancestor, left, right)
for key in set(key for d in dicts for key in d.keys()):
Expand Down

0 comments on commit 70e07aa

Please sign in to comment.