]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils: modelling: matching types in obj type validation
authorAleš <ales.mrazek@nic.cz>
Tue, 21 Sep 2021 23:37:41 +0000 (01:37 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 8 Apr 2022 14:17:53 +0000 (16:17 +0200)
- when obj and expected type match during type validation, full obj is returned

manager/knot_resolver_manager/utils/modelling.py

index a8940fd3ffdcac0006f71633a15bdd2ba39be4dd..64af2980dd3946a6f2e35f1a8c18f45925799f24 100644 (file)
@@ -144,6 +144,10 @@ def _validated_object_type(
         types = get_generic_type_arguments(cls)
         return tuple(_validated_object_type(typ, val, object_path=object_path) for typ, val in zip(types, obj))
 
+    # type of obj and cls type match
+    elif is_obj_type(obj, cls):
+        return obj
+
     # CustomValueType subclasses
     elif inspect.isclass(cls) and issubclass(cls, CustomValueType):
         if isinstance(obj, cls):
@@ -190,10 +194,12 @@ class SchemaNode:
             if val is not ...:
                 setattr(self, name, val)
                 used_keys.add(name)
-            
+
                 if hasattr(self, f"_{name}"):
                     # check, that the schema makes sense
-                    raise TypeError(f"{cls.__name__}.{name}: can't have both default value and transformation function at once. Use _PREVIOUS_SCHEMA...")
+                    raise TypeError(
+                        f"{cls.__name__}.{name}: can't have both default value and transformation function at once. Use _PREVIOUS_SCHEMA..."
+                    )
 
         return used_keys