ConfigUnit: fix static class variable inheritance
This commit is contained in:
parent
6994741c61
commit
949eec3dc9
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user