深度合并两个字典。override 中的值覆盖 base 中的值。 如果两边都是字典,递归合并。 对应源码: config.rs 中的 deep_merge_objects 函数
(base: dict, override: dict)
| 207 | # 其他部分继承自全局配置。 |
| 208 | |
| 209 | def deep_merge(base: dict, override: dict) -> dict: |
| 210 | """ |
| 211 | 深度合并两个字典。override 中的值覆盖 base 中的值。 |
| 212 | 如果两边都是字典,递归合并。 |
| 213 | |
| 214 | 对应源码: config.rs 中的 deep_merge_objects 函数 |
| 215 | """ |
| 216 | for key, value in override.items(): |
| 217 | if key in base and isinstance(base[key], dict) and isinstance(value, dict): |
| 218 | # 两边都是字典 → 递归合并 |
| 219 | deep_merge(base[key], value) |
| 220 | else: |
| 221 | # 否则直接覆盖 |
| 222 | base[key] = value |
| 223 | return base |
| 224 | |
| 225 | |
| 226 | # ============================================================ |