mate_common.datastructures.dict_utils module

This module provides dict manipulation functions.

mate_common.datastructures.dict_utils.recursive_merge(d1: Dict[mate_common.datastructures.dict_utils.T, Any], d2: Dict[mate_common.datastructures.dict_utils.T, Any]) Dict[mate_common.datastructures.dict_utils.T, Any]

Merge two dictionaries, merging any sub-dictionaries at the same key.

If the two dictionaries have the same key (path) but different values, the values in the second dictionary will be used.

Returns a freshly-allocated dict.

>>> recursive_merge({'foo': {'bar': 'baz'}}, {})
{'foo': {'bar': 'baz'}}
>>> recursive_merge({}, {'foo': {'bar': 'baz'}})
{'foo': {'bar': 'baz'}}
>>> recursive_merge({'foo': {'bar': 'baz'}}, {'foo': {'quux': 'asdf'}})
{'foo': {'bar': 'baz', 'quux': 'asdf'}}
>>> recursive_merge({'foo': {'bar': 'baz'}}, {'foo': {'bar': 'asdf'}})
{'foo': {'bar': 'asdf'}}
  • d1 (Dict[mate_common.datastructures.dict_utils.T, Any]) –

  • d2 (Dict[mate_common.datastructures.dict_utils.T, Any]) –

Return type

Dict[mate_common.datastructures.dict_utils.T, Any]