mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-04-29 03:00:45 -04:00
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: hieptl <hieptl.developer@gmail.com> Co-authored-by: tofarr <tofarr@gmail.com>
25 lines
706 B
Python
25 lines
706 B
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def deep_merge(
|
|
base: dict[str, Any],
|
|
updates: dict[str, Any],
|
|
) -> dict[str, Any]:
|
|
"""Recursively merge *updates* into a shallow copy of *base*.
|
|
|
|
* Nested dicts are merged recursively.
|
|
* ``None`` values in *updates* remove the corresponding key.
|
|
* All other values overwrite.
|
|
"""
|
|
result: dict[str, Any] = dict(base)
|
|
for key, value in updates.items():
|
|
if value is None:
|
|
result.pop(key, None)
|
|
elif isinstance(value, dict) and isinstance(result.get(key), dict):
|
|
result[key] = deep_merge(result[key], value)
|
|
else:
|
|
result[key] = value
|
|
return result
|