MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / deep_merge

Function deep_merge

openhands/app_server/utils/jsonpatch_compat.py:10–28  ·  view source on GitHub ↗

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.

(
    base: dict[str, Any],
    updates: dict[str, Any],
)

Source from the content-addressed store, hash-verified

8
9
10def deep_merge(
11 base: dict[str, Any],
12 updates: dict[str, Any],
13) -> dict[str, Any]:
14 """Recursively merge *updates* into a shallow copy of *base*.
15
16 * Nested dicts are merged recursively.
17 * ``None`` values in *updates* remove the corresponding key.
18 * All other values overwrite.
19 """
20 result: dict[str, Any] = dict(base)
21 for key, value in updates.items():
22 if value is None:
23 result.pop(key, None)
24 elif isinstance(value, dict) and isinstance(result.get(key), dict):
25 result[key] = deep_merge(result[key], value)
26 else:
27 result[key] = value
28 return result
29
30
31def deep_merge_with_wholesale_keys(

Callers 12

updateMethod · 0.90
test_basic_mergeMethod · 0.90
test_nested_mergeMethod · 0.90
test_none_removes_keyMethod · 0.90
loadMethod · 0.90
storeMethod · 0.90
_validate_org_versionMethod · 0.90
create_orgMethod · 0.90

Calls 1

getMethod · 0.45

Tested by 4

test_basic_mergeMethod · 0.72
test_nested_mergeMethod · 0.72
test_none_removes_keyMethod · 0.72