def _dict_merge()

in src/hpc/autoscale/util.py [0:0]


def _dict_merge(d1: Dict, d2: Dict) -> Dict:
    ret = {}

    for k, v1 in d1.items():
        if k not in d2:
            ret[k] = v1
            continue

        v2 = d2[k]
        if type(v1) != type(v2):
            ret[k] = v2
            continue

        if isinstance(v1, list):
            ret[k] = []
            for v0 in v1 + v2:
                if v0 not in ret[k]:
                    ret[k].append(v0)

        elif isinstance(v1, dict):
            ret[k] = _dict_merge(v1, v2)
        else:
            ret[k] = v2

    for k, v2 in d2.items():
        if k not in ret:
            ret[k] = v2

    return ret