Add unconnected database support
Also adds a helper for doing nested config parsing since we're getting more and more
This commit is contained in:
parent
cee708f4d8
commit
0b3b6f50fe
5 changed files with 53 additions and 12 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any
|
||||
from typing import Any, TypeVar, Callable
|
||||
|
||||
|
||||
class ConfigParseError(Exception):
|
||||
|
|
@ -18,3 +18,14 @@ def assert_key_of_type(config: dict[str, Any], key: str, kind: Any):
|
|||
|
||||
if not isinstance(config[key], kind):
|
||||
raise ConfigParseError([key], f'type of "{key}" was {type(config[key])}, expected {kind}')
|
||||
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
def parse_nested_config(config: dict[str, Any], key: str, parse: Callable[[dict[str, Any]], T]) -> T:
|
||||
assert_key_of_type(config, key, dict)
|
||||
try:
|
||||
return parse(config[key])
|
||||
except ConfigParseError as e:
|
||||
raise ConfigParseError([key, *e.keypath], e.issue)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue