Add more kinds of values

Also fixes some type signatures
This commit is contained in:
Joscha 2019-06-20 19:47:45 +00:00
parent 9d20aaa394
commit ff4ee93ade

View file

@ -42,20 +42,20 @@ class TransparentConfig:
# Special config reading and writing classes # Special config reading and writing classes
class Kind(Enum): class Kind(Enum):
BOOL = auto()
DICT = auto()
FLOAT = auto()
INT = auto() INT = auto()
STR = auto() STR = auto()
FLOAT = auto()
RAW = auto() RAW = auto()
def matches(self, value: Any) -> bool: def matches(self, value: Any) -> bool:
if self == self.INT: if self == self.BOOL: return type(value) is bool
return type(value) is int elif self == self.DICT: return type(value) is dict
elif self == self.STR: elif self == self.FLOAT: return type(value) is float
return type(value) is str elif self == self.INT: return type(value) is int
elif self == self.FLOAT: elif self == self.STR: return type(value) is str
return type(value) is float elif self == self.RAW: return True
elif self == self.RAW:
return True
return False return False
@ -78,8 +78,6 @@ class Option:
if not condition(value): if not condition(value):
raise ConfigValueException(error_message) raise ConfigValueException(error_message)
T = TypeVar("T", bound=TransparentConfig)
class TreeLoader: class TreeLoader:
def __init__(self) -> None: def __init__(self) -> None:
@ -96,7 +94,7 @@ class TreeLoader:
return config return config
def load_to(self, config: T, data: Any) -> T: def load_to(self, config: TransparentConfig, data: Any) -> None:
errors = [] errors = []
for name, option in self._options.items(): for name, option in self._options.items():
@ -112,8 +110,6 @@ class TreeLoader:
if errors: if errors:
raise ConfigValueException(errors) raise ConfigValueException(errors)
else:
return config
@classmethod @classmethod
def export(cls, config: TransparentConfig) -> Any: def export(cls, config: TransparentConfig) -> Any: