calling the constructor of the appropriate type on the field value. The only limitation
is that the value MUST NOT be `None`.
- Example:
- ```
- class A(DataParser):
- field: MyBaseCustomType
-
- A.from_json('{"field": "value"}') == A(field=MyBaseCustomType("value"))
- ```
-
There is no validation done on the wrapped value. The only condition is that
it can't be `None`. If you want to perform any validation during creation,
raise a `ValueError` in case of errors.
pass
def __int__(self) -> int:
- raise NotImplementedError("BaseCustomType return 'int()' value is not implemented.")
+ raise NotImplementedError(f" return 'int()' value for {type(self).__name__} is not implemented.")
def __str__(self) -> str:
- raise NotImplementedError("BaseCustomType return 'str()' value is not implemented.")
+ raise NotImplementedError(f"return 'str()' value for {type(self).__name__} is not implemented.")
def serialize(self) -> Any:
"""
It's not necessary to return the same structure that was given as an input. It only has
to be the same semantically.
"""
- raise NotImplementedError(f"{type(self).__name__}'s' 'to_dict()' not implemented.")
+ raise NotImplementedError(f"{type(self).__name__}'s' 'serialize()' not implemented.")
@classmethod
def json_schema(cls: Type["BaseCustomType"]) -> Dict[Any, Any]:
class BaseSchema(Serializable):
"""
- Class for modelling configuration schema. It somewhat resembles standard dataclasses with additional
+ Base class for modeling configuration schema. It somewhat resembles standard dataclasses with additional
functionality:
* type validation
To create an instance of this class, you have to provide source data in the form of dict-like object.
Generally, we expect `ParsedTree`, raw dict or another `BaseSchema` instance. The provided data object
- is traversed, transformed and validated before assigned to the appropriate fields.
+ is traversed, transformed and validated before assigned to the appropriate fields (attributes).
Fields (attributes)
===================
Using this, you can convert any input values into any type and field you want. To make the conversion easier
to write, you could also specify a special class variable called `_LAYER` pointing to another
- BaseSchema class. This causes the source object to be first parsed as the specified BaseSchema and after that
+ BaseSchema class. This causes the source object to be first parsed as the specified additional layer of BaseSchema and after that
used a source for this class. This therefore allows nesting of transformation functions.
Validation
class ParsedTree:
"""
- Simple wrapper for parsed data. Changes internal naming convention (snake case)
- to external (dashes) on the fly.
+ Simple wrapper for parsed data.
+ Changes external naming convention (hyphen separator) to internal (snake_case) on the fly.
IMMUTABLE, DO NOT MODIFY
"""