From 4519977cfe7c0a515ddbcabcc337ab9006af45d5 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 11 Jul 2024 10:06:31 -0600 Subject: [PATCH] misc.deep_merge: Rewrite for readability Partially enabled by not passing MappingProxyType to it any longer. Signed-off-by: Zack Cerza --- teuthology/misc.py | 16 ++++++---------- teuthology/suite/merge.py | 5 ++--- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/teuthology/misc.py b/teuthology/misc.py index 2a9a73f507..c3d324a4bc 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -18,7 +18,6 @@ import re from sys import stdin import pprint import datetime -from types import MappingProxyType from tarfile import ReadError @@ -997,21 +996,18 @@ def deep_merge(a: DeepMerge, b: DeepMerge) -> DeepMerge: """ if b is None: return a - elif isinstance(a, list): + if a is None: + return deep_merge(b.__class__(), b) + if isinstance(a, list): assert isinstance(b, list) a.extend(b) return a - elif isinstance(a, dict): - assert isinstance(b, dict) or isinstance(b, MappingProxyType) + if isinstance(a, dict): + assert isinstance(b, dict) for (k, v) in b.items(): a[k] = deep_merge(a.get(k), v) return a - elif isinstance(b, dict) or isinstance(b, list): - return deep_merge(b.__class__(), b) - elif isinstance(b, MappingProxyType): - return dict() | b - else: - return b + return b def get_valgrind_args(testdir, name, preamble, v, exit_on_first_error=True): diff --git a/teuthology/suite/merge.py b/teuthology/suite/merge.py index 4ae9e05bf7..f13058e47d 100644 --- a/teuthology/suite/merge.py +++ b/teuthology/suite/merge.py @@ -14,7 +14,7 @@ log = logging.getLogger(__name__) TEUTHOLOGY_TEMPLATE = MappingProxyType({ "teuthology": { "fragments_dropped": [], - "meta": MappingProxyType({}), + "meta": {}, "postmerge": [], } }) @@ -114,7 +114,6 @@ def config_merge(configs, suite_name=None, **kwargs): postmerge scripts. Logically, if a filter matches then reject will drop the entire job (config) from the list. """ - seed = kwargs.setdefault('seed', 1) if not isinstance(seed, int): log.debug("no valid seed input: using 1") @@ -130,7 +129,7 @@ def config_merge(configs, suite_name=None, **kwargs): desc = combine_path(suite_name, desc) yaml_complete_obj = {} - deep_merge(yaml_complete_obj, TEUTHOLOGY_TEMPLATE) + deep_merge(yaml_complete_obj, dict(TEUTHOLOGY_TEMPLATE)) for path in paths: if path not in yaml_cache: with open(path) as f: -- 2.39.5