Tweak config._recursive_merge (#103850)

This commit is contained in:
Erik Montnemery 2023-11-12 19:06:12 +01:00 committed by GitHub
parent 01b3e0c49e
commit 6303366cf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -724,15 +724,15 @@ def _identify_config_schema(module: ComponentProtocol) -> str | None:
return None return None
def _recursive_merge(conf: dict[str, Any], package: dict[str, Any]) -> bool | str: def _recursive_merge(conf: dict[str, Any], package: dict[str, Any]) -> str | None:
"""Merge package into conf, recursively.""" """Merge package into conf, recursively."""
error: bool | str = False duplicate_key: str | None = None
for key, pack_conf in package.items(): for key, pack_conf in package.items():
if isinstance(pack_conf, dict): if isinstance(pack_conf, dict):
if not pack_conf: if not pack_conf:
continue continue
conf[key] = conf.get(key, OrderedDict()) conf[key] = conf.get(key, OrderedDict())
error = _recursive_merge(conf=conf[key], package=pack_conf) duplicate_key = _recursive_merge(conf=conf[key], package=pack_conf)
elif isinstance(pack_conf, list): elif isinstance(pack_conf, list):
conf[key] = cv.remove_falsy( conf[key] = cv.remove_falsy(
@ -743,7 +743,7 @@ def _recursive_merge(conf: dict[str, Any], package: dict[str, Any]) -> bool | st
if conf.get(key) is not None: if conf.get(key) is not None:
return key return key
conf[key] = pack_conf conf[key] = pack_conf
return error return duplicate_key
async def merge_packages_config( async def merge_packages_config(
@ -818,10 +818,10 @@ async def merge_packages_config(
) )
continue continue
error = _recursive_merge(conf=config[comp_name], package=comp_conf) duplicate_key = _recursive_merge(conf=config[comp_name], package=comp_conf)
if error: if duplicate_key:
_log_pkg_error( _log_pkg_error(
pack_name, comp_name, config, f"has duplicate key '{error}'" pack_name, comp_name, config, f"has duplicate key '{duplicate_key}'"
) )
return config return config