Allow configs with None values

This commit is contained in:
Nuno Campos 2023-10-17 15:23:58 +01:00
parent b0d5882fe1
commit 19319e1746

View File

@ -159,17 +159,25 @@ def patch_config(
def merge_configs(*configs: Optional[RunnableConfig]) -> RunnableConfig:
base: RunnableConfig = {}
# Even though the keys aren't literals this is correct
# because both dicts are same type
for config in (c for c in configs if c is not None):
for key in config:
if key == "metadata":
base[key] = {**base.get(key, {}), **config[key]} # type: ignore
base[key] = { # type: ignore
**base.get(key, {}), # type: ignore
**(config.get(key) or {}), # type: ignore
}
elif key == "tags":
base[key] = list(set(base.get(key, []) + config[key])) # type: ignore
base[key] = list( # type: ignore
set(base.get(key, []) + (config.get(key) or [])), # type: ignore
)
elif key == "configurable":
base[key] = {**base.get(key, {}), **config[key]} # type: ignore
base[key] = { # type: ignore
**base.get(key, {}), # type: ignore
**(config.get(key) or {}), # type: ignore
}
else:
# Even though the keys aren't literals this is correct
# because both dicts are same type
base[key] = config[key] or base.get(key) # type: ignore
return base