Set up the bones of a Flask app with configuration

This commit is contained in:
Campbell Alden 2026-07-30 22:45:25 +09:00
parent 0909fd7e99
commit a7fdd6cbd0
7 changed files with 131 additions and 1 deletions

20
src/config/parse.py Normal file
View file

@ -0,0 +1,20 @@
from typing import Any
class ConfigParseError(Exception):
"""An error for when parsing a config fails"""
def __init__(self, keypath: list[str], issue: str):
path = '.'.join(keypath)
message = f'{path}: {issue}'
super().__init__(message)
self.keypath = keypath
self.issue = issue
def assert_key_of_type(config: dict[str, Any], key: str, kind: Any):
if key not in config:
raise ConfigParseError([key], 'missing')
if not isinstance(config[key], kind):
raise ConfigParseError([key], f'type of "{key}" was {type(config[key])}, expected {kind}')