diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-09-07 01:32:21 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-09-07 01:32:21 +0300 |
commit | 949eec3dc9cd37c70fb553e3e3f57decc8c89afc (patch) | |
tree | 3dec4a4065e6bd2dcab2680613daddcc7a0775a2 /include/py/homekit/config/config.py | |
parent | 6994741c612e74a28683ca7cdd7b14f9876a0305 (diff) |
ConfigUnit: fix static class variable inheritance
Diffstat (limited to 'include/py/homekit/config/config.py')
-rw-r--r-- | include/py/homekit/config/config.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/include/py/homekit/config/config.py b/include/py/homekit/config/config.py index 29364af..773de1e 100644 --- a/include/py/homekit/config/config.py +++ b/include/py/homekit/config/config.py @@ -52,6 +52,8 @@ class BaseConfigUnit(ABC): def load_from(self, path: str): with open(path, 'r') as fd: self._data = yaml.safe_load(fd) + if self._data is None: + raise TypeError(f'config file {path} is empty') def get(self, key: Optional[str] = None, @@ -78,6 +80,10 @@ class ConfigUnit(BaseConfigUnit): _instance = None + def __init_subclass__(cls, **kwargs): + super().__init_subclass__(**kwargs) + cls._instance = None + def __new__(cls, *args, **kwargs): if cls._instance is None: cls._instance = super(ConfigUnit, cls).__new__(cls, *args, **kwargs) @@ -200,7 +206,7 @@ class AppConfigUnit(ConfigUnit): def logging_get_fmt(self) -> Optional[str]: try: return self['logging']['default_fmt'] - except KeyError: + except (KeyError, TypeError): return self._logging_fmt def logging_set_file(self, file: str) -> None: @@ -209,7 +215,7 @@ class AppConfigUnit(ConfigUnit): def logging_get_file(self) -> Optional[str]: try: return self['logging']['file'] - except KeyError: + except (KeyError, TypeError): return self._logging_file def logging_set_verbose(self): @@ -218,7 +224,7 @@ class AppConfigUnit(ConfigUnit): def logging_is_verbose(self) -> bool: try: return bool(self['logging']['verbose']) - except KeyError: + except (KeyError, TypeError): return self._logging_verbose @@ -271,7 +277,9 @@ class Config: and not isinstance(name, bool) \ and issubclass(name, AppConfigUnit) or name == AppConfigUnit: self.app_name = name.NAME + print(self.app_config) self.app_config = name() + print(self.app_config) app_config = self.app_config else: self.app_name = name if isinstance(name, str) else None |