]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
fixed code issues reported by static analysis
authorVasek Sraier <git@vakabus.cz>
Wed, 3 Nov 2021 12:43:58 +0000 (13:43 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 8 Apr 2022 14:17:53 +0000 (16:17 +0200)
manager/knot_resolver_manager/utils/modelling.py
manager/tests/datamodel/test_config_schema.py

index 03aa947dd33ac7018217e367549237b25ea49895..29782bbee9817f85cae39bf7b58e68f9b25d6e8d 100644 (file)
@@ -1,5 +1,4 @@
 import inspect
-from re import match
 from typing import Any, Dict, List, Optional, Set, Tuple, Type, Union, cast
 
 from knot_resolver_manager.exceptions import DataException, SchemaException
@@ -52,21 +51,21 @@ class Serializable:
             or (inspect.isclass(typ) and issubclass(typ, CustomValueType))
             or (inspect.isclass(typ) and issubclass(typ, SchemaNode))
             or (is_optional(typ) and Serializable.is_serializable(get_optional_inner_type(typ)))
-            or (is_union(typ) and all_matches(lambda t: Serializable.is_serializable(t), get_generic_type_arguments(typ)))
+            or (is_union(typ) and all_matches(Serializable.is_serializable, get_generic_type_arguments(typ)))
         )
-    
+
     @staticmethod
     def serialize(obj: Any, typ: Type[Any]) -> Any:
         if inspect.isclass(typ) and issubclass(typ, Serializable):
             return cast(Serializable, obj).to_dict()
-        
+
         elif inspect.isclass(typ) and issubclass(typ, CustomValueType):
             return cast(CustomValueType, obj).serialize()
-        
+
         elif inspect.isclass(typ) and issubclass(typ, SchemaNode):
             node = cast(SchemaNode, obj)
             return node.serialize()
-        
+
         elif is_list(typ):
             lst = cast(List[Any], obj)
             res: List[Any] = [Serializable.serialize(i, get_generic_type_argument(typ)) for i in lst]
@@ -509,7 +508,7 @@ class SchemaNode:
         schema["properties"] = _get_properties_schema(cls)
 
         return schema
-    
+
     def serialize(self) -> Dict[Any, Any]:
         res: Dict[Any, Any] = {}
         cls = self.__class__
index 852e6eb04df07747b7771219bbbefabaecf7dfbd..cbce9e2de5cb1e8aa76e55a610c4dac94cd60c7f 100644 (file)
@@ -1,5 +1,6 @@
 import json
 from typing import Any, Dict, cast
+
 from knot_resolver_manager.datamodel import KresConfig
 from knot_resolver_manager.datamodel.types import IPv6Network96, TimeUnit
 
@@ -41,7 +42,7 @@ def test_dnssec_default_true():
 def test_json_schema():
     dct = KresConfig.json_schema()
 
-    def recser(obj: Any, path: str = ''):
+    def recser(obj: Any, path: str = ""):
         if not isinstance(obj, dict):
             return
         else:
@@ -52,7 +53,5 @@ def test_json_schema():
                 _ = json.dumps(obj)
             except BaseException as e:
                 raise Exception(f"failed to serialize '{path}'") from e
-    
-    recser(dct)
-
 
+    recser(dct)