Load to existing config
This commit is contained in:
parent
ae1bbc63e7
commit
9d20aaa394
1 changed files with 4 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from enum import Enum, auto
|
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",
|
__all__ = ["ConfigException", "ConfigValueException", "TransparentConfig",
|
||||||
"Kind", "Condition", "Option", "TreeLoader"]
|
"Kind", "Condition", "Option", "TreeLoader"]
|
||||||
|
|
@ -78,6 +78,8 @@ 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:
|
||||||
|
|
@ -94,8 +96,7 @@ class TreeLoader:
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def load(self, data: Any) -> TransparentConfig:
|
def load_to(self, config: T, data: Any) -> T:
|
||||||
config = TransparentConfig()
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
for name, option in self._options.items():
|
for name, option in self._options.items():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue