From dd344a4321f8c705f43a35335930feb0cc16ac7b Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Tue, 9 Jul 2024 12:27:19 +0200 Subject: [PATCH] Refactor --- kpops/utils/dict_differ.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/kpops/utils/dict_differ.py b/kpops/utils/dict_differ.py index 90315a7d2..ebb9e562f 100644 --- a/kpops/utils/dict_differ.py +++ b/kpops/utils/dict_differ.py @@ -1,10 +1,10 @@ from __future__ import annotations -from collections.abc import Mapping +from collections.abc import Mapping, MutableMapping from dataclasses import dataclass from difflib import Differ from enum import Enum -from typing import TYPE_CHECKING, Generic, TypeVar +from typing import TYPE_CHECKING, Any, Generic, TypeVar import typer import yaml @@ -79,16 +79,17 @@ def __find_changed_key(key_1: list[str] | str, key_2: str = "") -> str: return f"{key_1}.{key_2}" -def render_diff(d1: Mapping, d2: Mapping, ignore: set[str] | None = None) -> str | None: - d1 = dict(d1) - d2 = dict(d2) - - def del_ignored_keys(d: dict) -> None: +def render_diff( + d1: MutableMapping[str, Any], + d2: MutableMapping[str, Any], + ignore: set[str] | None = None, +) -> str | None: + def del_ignored_keys(d: MutableMapping[str, Any]) -> None: """Delete key to be ignored, dictionary is modified in-place.""" if ignore: for i in ignore: key_path = i.split(".") - nested = d1 + nested = d try: for key in key_path[:-1]: nested = nested[key]