From 9d20aaa394dfc15f9b7ca277910ba193e7b4d21a Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 20 Jun 2019 17:44:26 +0000 Subject: [PATCH] Load to existing config --- cheuph/config.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cheuph/config.py b/cheuph/config.py index 7de9f28..b550a14 100644 --- a/cheuph/config.py +++ b/cheuph/config.py @@ -1,6 +1,6 @@ from dataclasses import dataclass, field from enum import Enum, auto -from typing import Any, Callable, Dict, List, Optional, Tuple +from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar __all__ = ["ConfigException", "ConfigValueException", "TransparentConfig", "Kind", "Condition", "Option", "TreeLoader"] @@ -78,6 +78,8 @@ class Option: if not condition(value): raise ConfigValueException(error_message) +T = TypeVar("T", bound=TransparentConfig) + class TreeLoader: def __init__(self) -> None: @@ -94,8 +96,7 @@ class TreeLoader: return config - def load(self, data: Any) -> TransparentConfig: - config = TransparentConfig() + def load_to(self, config: T, data: Any) -> T: errors = [] for name, option in self._options.items():