utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:central 作者: viniciuschiele 项目源码 文件源码
def merge_dict(target, *sources):
    """
    Merge the given list of `Mapping` objects into `target` object.
    :param MutableMapping target: The mapping to receive the merge.
    :param tuple sources: The list of `mapping` objects to be merged.
    """
    for source in sources:
        if not isinstance(target, MutableMapping):
            raise TypeError('target must be a dict')

        if not isinstance(source, Mapping):
            raise TypeError('data must be a dict')

        for key in source:
            target_value = target.get(key)
            source_value = source[key]

            if target_value is None or source_value is None:
                target[key] = source_value

            elif isinstance(target_value, Mapping) and isinstance(source_value, Mapping):
                merge_dict(target_value, source_value)

            else:
                target[key] = source_value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号