1414
1515import  importlib 
1616import  importlib .util 
17- import  itertools 
1817from  types  import  ModuleType 
19- from  typing  import  Any , Iterable ,  Tuple , Type 
18+ from  typing  import  Any , Tuple , Type 
2019
2120import  jsonschema 
2221
2322from  synapse .config ._base  import  ConfigError 
2423from  synapse .config ._util  import  json_error_to_config_error 
24+ from  synapse .types  import  StrSequence 
2525
2626
27- def  load_module (provider : dict , config_path : Iterable [ str ] ) ->  Tuple [Type , Any ]:
27+ def  load_module (provider : dict , config_path : StrSequence ) ->  Tuple [Type , Any ]:
2828    """Loads a synapse module with its config 
2929
3030    Args: 
@@ -39,9 +39,7 @@ def load_module(provider: dict, config_path: Iterable[str]) -> Tuple[Type, Any]:
3939
4040    modulename  =  provider .get ("module" )
4141    if  not  isinstance (modulename , str ):
42-         raise  ConfigError (
43-             "expected a string" , path = itertools .chain (config_path , ("module" ,))
44-         )
42+         raise  ConfigError ("expected a string" , path = tuple (config_path ) +  ("module" ,))
4543
4644    # We need to import the module, and then pick the class out of 
4745    # that, so we split based on the last dot. 
@@ -55,19 +53,17 @@ def load_module(provider: dict, config_path: Iterable[str]) -> Tuple[Type, Any]:
5553        try :
5654            provider_config  =  provider_class .parse_config (module_config )
5755        except  jsonschema .ValidationError  as  e :
58-             raise  json_error_to_config_error (
59-                 e , itertools .chain (config_path , ("config" ,))
60-             )
56+             raise  json_error_to_config_error (e , tuple (config_path ) +  ("config" ,))
6157        except  ConfigError  as  e :
6258            raise  _wrap_config_error (
6359                "Failed to parse config for module %r"  %  (modulename ,),
64-                 prefix = itertools . chain (config_path ,  ("config" ,) ),
60+                 prefix = tuple (config_path )  +   ("config" ,),
6561                e = e ,
6662            )
6763        except  Exception  as  e :
6864            raise  ConfigError (
6965                "Failed to parse config for module %r"  %  (modulename ,),
70-                 path = itertools . chain (config_path ,  ("config" ,) ),
66+                 path = tuple (config_path )  +   ("config" ,),
7167            ) from  e 
7268    else :
7369        provider_config  =  module_config 
@@ -92,17 +88,15 @@ def load_python_module(location: str) -> ModuleType:
9288    return  mod 
9389
9490
95- def  _wrap_config_error (
96-     msg : str , prefix : Iterable [str ], e : ConfigError 
97- ) ->  "ConfigError" :
91+ def  _wrap_config_error (msg : str , prefix : StrSequence , e : ConfigError ) ->  "ConfigError" :
9892    """Wrap a relative ConfigError with a new path 
9993
10094    This is useful when we have a ConfigError with a relative path due to a problem 
10195    parsing part of the config, and we now need to set it in context. 
10296    """ 
10397    path  =  prefix 
10498    if  e .path :
105-         path  =  itertools . chain (prefix ,  e .path )
99+         path  =  tuple (prefix )  +   tuple ( e .path )
106100
107101    e1  =  ConfigError (msg , path )
108102
0 commit comments