Skip to content

Commit

Permalink
Add support for merging list with dict
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaarreell committed Nov 19, 2024
1 parent f4fb82e commit dbebab8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions fmf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,29 @@ def _initialize(self, path):

def _merge_plus(self, data, key, value, prepend=False):
""" Handle extending attributes using the '+' suffix """

# Nothing to do if key not in parent
if key not in data:
data[key] = value
return

# Special handling for merging lists with dictionary
if isinstance(data[key], list) and isinstance(value, dict):
for list_item in data[key]:
if not isinstance(list_item, dict):
"MergeError: Item '{0}' in {1} must be a dictionary.".format(
list_item, self.name)
self._merge_special(list_item, value)
return
if isinstance(data[key], dict) and isinstance(value, list):
for list_item in value:
if not isinstance(list_item, dict):
"MergeError: Item '{0}' in {1} must be a dictionary.".format(
list_item, self.name)
self._merge_special(list_item, data[key])
data[key] = value
return

# Use the special merge for merging dictionaries
if type(data[key]) == type(value) == dict:
self._merge_special(data[key], value)
Expand Down

0 comments on commit dbebab8

Please sign in to comment.