def _union_copy(dict1, dict2):
    """
    Internal wrapper to keep one level of copying out of play, for efficiency.

    Only copies data on dict2, but will alter dict1.
    """

    for key, value in dict2.items():
        if key in dict1 and isinstance(value, dict):
            dict1[key] = _union_copy(dict1[key], value)
        else:
            dict1[key] = copy.deepcopy(value)
    return dict1
Internal wrapper to keep one level of copying out of play, for efficiency.

    Only copies data on dict2, but will alter dict1.