refactoring

This commit is contained in:
Maxim Devaev
2023-06-20 05:45:25 +03:00
parent db3f622023
commit a74044b086
3 changed files with 20 additions and 20 deletions

View File

@@ -19,10 +19,25 @@
# #
# ========================================================================== #
from typing import Optional
# =====
def yaml_merge(dest: dict, src: dict, src_name: str="") -> None:
""" Merges the source dictionary into the destination dictionary. """
# Checking if destination is None
if dest is None:
# We can't merge into a None
raise ValueError(f"Could not merge {src_name or 'config'} into None. The destination cannot be None")
# Checking if source is None or empty
if not src:
# If src is None or empty, there's nothing to merge
return
_merge(dest, src)
# ======
def _merge(dest: dict, src: dict) -> None:
for key in src:
if key in dest:
@@ -30,19 +45,3 @@ def _merge(dest: dict, src: dict) -> None:
_merge(dest[key], src[key])
continue
dest[key] = src[key]
def yaml_merge(dest: dict, src: dict, source_name: Optional[str]=None) -> None:
""" Merges the source dictionary into the destination dictionary. """
# Checking if destination is None
if dest is None:
# We can't merge into a None
raise ValueError(f"Could not merge {source_name} into None. The destination cannot be None")
# Checking if source is None or empty
if src is None:
# If src is None or empty, there's nothing to merge
return
_merge(dest, src)