From 9572f361755e83838a467d65ef22cfb68bb0c45c Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 23 May 2025 21:41:34 +0200 Subject: [PATCH] feat(persist/util): init parent_is_dict Check if a parent value is of type dict This utility is helpfull for cross checking of flattened dicts --- pkgs/clan-cli/clan_lib/persist/util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkgs/clan-cli/clan_lib/persist/util.py b/pkgs/clan-cli/clan_lib/persist/util.py index 03ea7f897..393fab2e0 100644 --- a/pkgs/clan-cli/clan_lib/persist/util.py +++ b/pkgs/clan-cli/clan_lib/persist/util.py @@ -134,6 +134,16 @@ def find_deleted_paths( return deleted_paths +def parent_is_dict(key: str, data: dict[str, Any]) -> bool: + parts = key.split(".") + while len(parts) > 1: + parts.pop() + parent_key = ".".join(parts) + if parent_key in data: + return isinstance(data[parent_key], dict) + return False + + def calc_patches( persisted: dict[str, Any], update: dict[str, Any],