#!/usr/bin/env python # -*- coding:utf-8 -*- # @FileName :data_utils.py # @Time :2025/5/21 16:16 # @Author :David # @Company: shenyang JY def deep_update(target, source): """ 递归将 source 字典的内容合并到 target 字典中 规则: 1. 若 key 在 target 和 source 中都存在,且值均为字典 → 递归合并 2. 若 key 在 source 中存在但 target 不存在 → 直接添加 3. 若 key 在 source 中存在且类型不为字典 → 覆盖 target 的值 """ for key, value in source.items(): # 如果 target 中存在该 key 且双方值都是字典 → 递归合并 if key in target and isinstance(target[key], dict) and isinstance(value, dict): deep_update(target[key], value) else: # 直接覆盖或添加(包括非字典类型或 target 中不存在该 key 的情况) target[key] = value return target if __name__ == "__main__": run_code = 0