Skip to content

Commit

Permalink
Reduce number of flatten logic branches
Browse files Browse the repository at this point in the history
  • Loading branch information
James McKinney committed Nov 27, 2018
1 parent c7ab621 commit 7ff6f66
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ocdsmerge/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ def flatten(obj, merge_rules=None, path=None, flattened=None):

if 'omitWhenMerged' in new_path_merge_rules:
continue
elif isinstance(value, list) and any(not isinstance(item, dict) for item in value):
# If it is an array containing non-objects, or it is neither a list nor an object, or is is `wholeListMerge`.
elif (isinstance(value, list) and any(not isinstance(item, dict) for item in value) or
not isinstance(value, (dict, list)) or 'wholeListMerge' in new_path_merge_rules):
flattened[new_path] = value
elif isinstance(value, (dict, list)) and 'wholeListMerge' not in new_path_merge_rules:
flatten(value, merge_rules, new_path, flattened)
else:
flattened[new_path] = value
flatten(value, merge_rules, new_path, flattened)

return flattened

Expand Down

0 comments on commit 7ff6f66

Please sign in to comment.