def dict_merge(d1: dict, d2: dict) -> dict:
    """Takes two dictionaries d1 and d2 and merges their data

    Example:

        >>> d1 = {'name': 'John', 'profile': {'group': 1, 'team': 42}}
        >>> d2 = {'profile': {'username': 'jj', 'group': 2}}
        >>> d3 = dict_merge(d1, d2)
        >>> d3 == {'name': 'John', 'profile': {'group': 2, 'team': 42, 'username': 'jj'}}
    """
    if not isinstance(d2, dict):
        return d1

    merged = d1.copy()

    for key, value in d2.items():
        if (
            key in merged
            and isinstance(merged[key], dict)
            and isinstance(value, dict)
        ):
            merged[key] = dict_merge(merged[key], value)
        else:
            merged[key] = value

    return merged
Takes two dictionaries d1 and d2 and merges their data

    Example:

        >>> d1 = {'name': 'John', 'profile': {'group': 1, 'team': 42}}
        >>> d2 = {'profile': {'username': 'jj', 'group': 2}}
        >>> d3 = dict_merge(d1, d2)
        >>> d3 == {'name': 'John', 'profile': {'group': 2, 'team': 42, 'username': 'jj'}}
    
dynaconf/typed/utils.py