pg.object_utils.merge_tree¶
Accessible via pg.object_utils.merge_tree
.
- merge_tree(dest, src, merge_fn=None, root_path=None)[source]¶
Deep merge two (maybe) hierarchical values.
- Return type:
- Parameters:
dest – Destination value.
src – Source value. When source value is a dict, it’s considered as a patch (delta) to the destination when destination is a dict or list. For other source types, it’s considered as a new value that will replace dest completely.
merge_fn –
- A function to handle value merge that will be called for updated
or added keys. If a branch is added/updated, the root of branch will be passed to merge_fn. the signature of function is: (path, left_value, right_value) ->
final_value If a key is only present in src dict, old_value is MISSING_VALUE. If a key is only present in dest dict, new_value is MISSING_VALUE. Otherwise both new_value and old_value are filled.
If final value is MISSING_VALUE, it will be removed from its parent collection.
root_path: KeyPath of dest.
- Returns:
Merged value.
- Raises:
KeyError – Dict keys are not integers when merging into a list.