diff --git a/cincoconfig/config.py b/cincoconfig/config.py index 3d230bd..07525eb 100644 --- a/cincoconfig/config.py +++ b/cincoconfig/config.py @@ -7,7 +7,6 @@ import sys from typing import Union, Any, Iterator, Tuple, Callable -from types import ModuleType from itertools import chain from .abc import Field, BaseConfig, BaseSchema, SchemaField, AnyField from .fields import IncludeField @@ -75,7 +74,7 @@ def __call__(self, validator: ConfigValidator = None) -> 'Config': ''' return Config(self, validator=validator) - def make_type(self, name: str, module: ModuleType = None, key_filename: str = None, + def make_type(self, name: str, module: str = None, key_filename: str = None, validator: ConfigValidator = None) -> type: ''' Create a new type that wraps this schema. This method should only be called once per @@ -109,7 +108,7 @@ def make_type(self, name: str, module: ModuleType = None, key_filename: str = No # same schema as above config = schema() - Item = item_schema.make_class('Item') + Item = item_schema.make_type('Item') item = Item(url='https://google.com', verify_ssl=False) config.endpoints.append(item) diff --git a/cincoconfig/fields.py b/cincoconfig/fields.py index ce103ef..ef60a73 100644 --- a/cincoconfig/fields.py +++ b/cincoconfig/fields.py @@ -567,16 +567,17 @@ def _validate(self, value: Any) -> Any: ''' if isinstance(self.field, BaseSchema): if isinstance(value, dict): - cfg = self.field() + cfg = self.field() # type: ignore + cfg._parent = self.cfg cfg.load_tree(value) - value = cfg - - if not isinstance(value, BaseConfig): - raise ValueError('invalid configuration') + elif isinstance(value, BaseConfig): + value._parent = self.cfg + value._validate() + cfg = value + else: + raise ValueError('invalid configuration object') - value._parent = self.cfg - value._validate() - return value + return cfg return self.field.validate(self.cfg, value)