From ff4ee93ade9d2232a85c341d21b6432c32ebb728 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 20 Jun 2019 19:47:45 +0000 Subject: [PATCH] Add more kinds of values Also fixes some type signatures --- cheuph/config.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/cheuph/config.py b/cheuph/config.py index b550a14..ea6fd15 100644 --- a/cheuph/config.py +++ b/cheuph/config.py @@ -42,20 +42,20 @@ class TransparentConfig: # Special config reading and writing classes class Kind(Enum): + BOOL = auto() + DICT = auto() + FLOAT = auto() INT = auto() STR = auto() - FLOAT = auto() RAW = auto() def matches(self, value: Any) -> bool: - if self == self.INT: - return type(value) is int - elif self == self.STR: - return type(value) is str - elif self == self.FLOAT: - return type(value) is float - elif self == self.RAW: - return True + if self == self.BOOL: return type(value) is bool + elif self == self.DICT: return type(value) is dict + elif self == self.FLOAT: return type(value) is float + elif self == self.INT: return type(value) is int + elif self == self.STR: return type(value) is str + elif self == self.RAW: return True return False @@ -78,8 +78,6 @@ class Option: if not condition(value): raise ConfigValueException(error_message) -T = TypeVar("T", bound=TransparentConfig) - class TreeLoader: def __init__(self) -> None: @@ -96,7 +94,7 @@ class TreeLoader: return config - def load_to(self, config: T, data: Any) -> T: + def load_to(self, config: TransparentConfig, data: Any) -> None: errors = [] for name, option in self._options.items(): @@ -112,8 +110,6 @@ class TreeLoader: if errors: raise ConfigValueException(errors) - else: - return config @classmethod def export(cls, config: TransparentConfig) -> Any: