import copy


def dict_merge(target, source):
    """Deep merge for dicts.

    Works like dict.update() that recursively updates any dict values present in
    both parameters.

    Args:
        target (dict): Values to be overwritten by corresponding values from
            `source`.
        source (dict): Overriding values. Not changed by call.

    Returns:
        `target` with values overwritten from those in `source` at any and all
        levels of nested dicts.
    """
    if not isinstance(source, dict):
        return source
    for k, v in source.items():
        if k in target and isinstance(target[k], dict):
            dict_merge(target[k], v)
        else:
            target[k] = copy.deepcopy(v)
    return target