From: Vasek Sraier Date: Wed, 3 Nov 2021 12:43:58 +0000 (+0100) Subject: fixed code issues reported by static analysis X-Git-Tag: v6.0.0a1~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1f82ab7142409456c8d0271b04dcd25a8dc0a17;p=thirdparty%2Fknot-resolver.git fixed code issues reported by static analysis --- diff --git a/manager/knot_resolver_manager/utils/modelling.py b/manager/knot_resolver_manager/utils/modelling.py index 03aa947dd..29782bbee 100644 --- a/manager/knot_resolver_manager/utils/modelling.py +++ b/manager/knot_resolver_manager/utils/modelling.py @@ -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__ diff --git a/manager/tests/datamodel/test_config_schema.py b/manager/tests/datamodel/test_config_schema.py index 852e6eb04..cbce9e2de 100644 --- a/manager/tests/datamodel/test_config_schema.py +++ b/manager/tests/datamodel/test_config_schema.py @@ -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)