14
14
15
15
import importlib
16
16
import importlib .util
17
- import itertools
18
17
from types import ModuleType
19
- from typing import Any , Iterable , Tuple , Type
18
+ from typing import Any , Tuple , Type
20
19
21
20
import jsonschema
22
21
23
22
from synapse .config ._base import ConfigError
24
23
from synapse .config ._util import json_error_to_config_error
24
+ from synapse .types import StrSequence
25
25
26
26
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 ]:
28
28
"""Loads a synapse module with its config
29
29
30
30
Args:
@@ -39,9 +39,7 @@ def load_module(provider: dict, config_path: Iterable[str]) -> Tuple[Type, Any]:
39
39
40
40
modulename = provider .get ("module" )
41
41
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" ,))
45
43
46
44
# We need to import the module, and then pick the class out of
47
45
# 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]:
55
53
try :
56
54
provider_config = provider_class .parse_config (module_config )
57
55
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" ,))
61
57
except ConfigError as e :
62
58
raise _wrap_config_error (
63
59
"Failed to parse config for module %r" % (modulename ,),
64
- prefix = itertools . chain (config_path , ("config" ,) ),
60
+ prefix = tuple (config_path ) + ("config" ,),
65
61
e = e ,
66
62
)
67
63
except Exception as e :
68
64
raise ConfigError (
69
65
"Failed to parse config for module %r" % (modulename ,),
70
- path = itertools . chain (config_path , ("config" ,) ),
66
+ path = tuple (config_path ) + ("config" ,),
71
67
) from e
72
68
else :
73
69
provider_config = module_config
@@ -92,17 +88,15 @@ def load_python_module(location: str) -> ModuleType:
92
88
return mod
93
89
94
90
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" :
98
92
"""Wrap a relative ConfigError with a new path
99
93
100
94
This is useful when we have a ConfigError with a relative path due to a problem
101
95
parsing part of the config, and we now need to set it in context.
102
96
"""
103
97
path = prefix
104
98
if e .path :
105
- path = itertools . chain (prefix , e .path )
99
+ path = tuple (prefix ) + tuple ( e .path )
106
100
107
101
e1 = ConfigError (msg , path )
108
102
0 commit comments