]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: utils: modeling: docstrings updates
authorAleš Mrázek <ales.mrazek@nic.cz>
Wed, 13 Jul 2022 10:39:43 +0000 (12:39 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Wed, 13 Jul 2022 10:39:43 +0000 (12:39 +0200)
-

manager/knot_resolver_manager/utils/modeling/base_custom_type.py
manager/knot_resolver_manager/utils/modeling/base_schema.py
manager/knot_resolver_manager/utils/modeling/parsing.py

index ccde09992e315666c3e2dcc4ab361673df478775..f35b011b7a718905c16fc7fefa122b53a7fb4329 100644 (file)
@@ -8,14 +8,6 @@ class BaseCustomType:
     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.
@@ -25,10 +17,10 @@ class BaseCustomType:
         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:
         """
@@ -37,7 +29,7 @@ class BaseCustomType:
         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]:
index 9278c2fcef4a221063b15593a87408925e1ea04f..16bfceb1a4ad39308794326fe7d5f953f0704e4c 100644 (file)
@@ -411,7 +411,7 @@ def _create_untouchable(name: str) -> object:
 
 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
@@ -419,7 +419,7 @@ class BaseSchema(Serializable):
 
     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)
     ===================
@@ -446,7 +446,7 @@ class BaseSchema(Serializable):
 
     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
index 27ad37c62c999a03f596487e8489d8edcce6722c..e3812456109d0d893b86fdc75a9ec132f7da4c23 100644 (file)
@@ -14,8 +14,8 @@ from .types import is_internal_field_name
 
 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
     """