]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc.deep_merge,merge_configs: Add type hinting
authorZack Cerza <zack@redhat.com>
Thu, 11 Jul 2024 16:06:30 +0000 (10:06 -0600)
committerZack Cerza <zack@redhat.com>
Thu, 11 Jul 2024 22:48:31 +0000 (16:48 -0600)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/misc.py

index a1b3cf6819f1e7d8c23a3e4eadb54dc0ce29a18e..2a9a73f5072bc6a35d7e5f66f83c4784ac16e815 100644 (file)
@@ -22,7 +22,7 @@ from types import MappingProxyType
 
 from tarfile import ReadError
 
-from typing import Optional
+from typing import Optional, TypeVar
 
 from teuthology.util.compat import urljoin, urlopen, HTTPError
 
@@ -110,7 +110,7 @@ def config_file(string):
     return config_dict
 
 
-def merge_configs(config_paths):
+def merge_configs(config_paths) -> dict:
     """ Takes one or many paths to yaml config files and merges them
         together, returning the result.
     """
@@ -123,7 +123,7 @@ def merge_configs(config_paths):
             continue
         else:
             with open(conf_path) as partial_file:
-                partial_dict = yaml.safe_load(partial_file)
+                partial_dict: dict = yaml.safe_load(partial_file)
         try:
             conf_dict = deep_merge(conf_dict, partial_dict)
         except Exception:
@@ -986,7 +986,8 @@ def replace_all_with_clients(cluster, config):
     return norm_config
 
 
-def deep_merge(a, b):
+DeepMerge = TypeVar('DeepMerge')
+def deep_merge(a: DeepMerge, b: DeepMerge) -> DeepMerge:
     """
     Deep Merge.  If a and b are both lists, all elements in b are
     added into a.  If a and b are both dictionaries, elements in b are
@@ -1008,7 +1009,7 @@ def deep_merge(a, b):
     elif isinstance(b, dict) or isinstance(b, list):
         return deep_merge(b.__class__(), b)
     elif isinstance(b, MappingProxyType):
-        return deep_merge(dict(), b)
+        return dict() | b
     else:
         return b