diff --git a/pyproject.toml b/pyproject.toml index bcc81ae..e89171b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "resotoclient" -version = "1.6.0" +version = "1.6.1" description = "Resoto Python client library" authors = ["Some Engineering Inc."] license = "Apache-2.0" diff --git a/resotoclient/__init__.py b/resotoclient/__init__.py index 30deb07..bf5f013 100644 --- a/resotoclient/__init__.py +++ b/resotoclient/__init__.py @@ -7,14 +7,12 @@ Optional, List, Tuple, - Sequence, Mapping, Type, AsyncIterator, TypeVar, Awaitable, Callable, - cast, ) from types import TracebackType from resotoclient.models import ( @@ -246,7 +244,7 @@ def get_node(self, node_id: str, graph: str = "resoto") -> JsObject: def delete_node(self, node_id: str, graph: str = "resoto") -> None: return self._await(lambda c: c.delete_node(node_id, graph)) - def patch_nodes(self, nodes: Sequence[JsObject], graph: str = "resoto") -> List[JsObject]: + def patch_nodes(self, nodes: List[JsObject], graph: str = "resoto") -> List[JsObject]: return self._await(lambda c: c.patch_nodes(nodes, graph)) def merge_graph(self, update: List[JsObject], graph: str = "resoto") -> GraphUpdate: @@ -404,7 +402,7 @@ def dataframe(self, search: str, section: Optional[str] = "reported", graph: str def extract_node(node: JsObject) -> Optional[JsObject]: node_data = node - if not isinstance(node_data, dict): + if not node_data: return None if aggregate_search: if flatten and "group" in node_data and isinstance(node_data["group"], dict): @@ -416,7 +414,7 @@ def extract_node(node: JsObject) -> Optional[JsObject]: if flatten: if not "reported" in node or not isinstance(node["reported"], dict): return None - node_data = cast(Dict[str, Any], node["reported"]) + node_data = node["reported"] for k, v in node.items(): if isinstance(v, dict) and k != "reported": node_data[k] = v diff --git a/resotoclient/async_client.py b/resotoclient/async_client.py index 0157a10..67fd46e 100644 --- a/resotoclient/async_client.py +++ b/resotoclient/async_client.py @@ -9,7 +9,6 @@ Optional, List, Tuple, - Sequence, Type, ) from types import TracebackType @@ -223,7 +222,7 @@ async def delete_node(self, node_id: str, graph: str = "resoto") -> None: else: raise AttributeError(await response.text()) - async def patch_nodes(self, nodes: Sequence[JsObject], graph: str = "resoto") -> List[JsObject]: + async def patch_nodes(self, nodes: List[JsObject], graph: str = "resoto") -> List[JsObject]: response = await self._patch( f"/graph/{graph}/nodes", json=nodes, diff --git a/resotoclient/json_utils.py b/resotoclient/json_utils.py index b13ddcf..a0124e8 100644 --- a/resotoclient/json_utils.py +++ b/resotoclient/json_utils.py @@ -1,6 +1,7 @@ -from typing import Optional, Type, TypeVar, Any -import jsons import json +from typing import Optional, Type, TypeVar + +import jsons from resotoclient.models import JsValue @@ -29,9 +30,3 @@ def json_dump( return jsons.dump(obj, cls) # type: ignore -def __identity(obj: JsValue, *args: Any, **kwargs: Any) -> JsValue: - return obj - - -jsons.set_serializer(__identity, JsValue) -jsons.set_deserializer(__identity, JsValue) diff --git a/resotoclient/models.py b/resotoclient/models.py index 40bffad..4f15f30 100644 --- a/resotoclient/models.py +++ b/resotoclient/models.py @@ -1,10 +1,10 @@ from dataclasses import dataclass, field -from typing import List, Optional, Mapping, Sequence, Union, Dict from datetime import timedelta from enum import Enum +from typing import List, Optional, Mapping, Union, Dict, Any -JsValue = Union[None, int, str, float, bool, Sequence["JsValue"], Mapping[str, "JsValue"]] -JsObject = Mapping[str, JsValue] +JsValue = Union[None, int, str, float, bool, List[Any], Dict[str, Any]] +JsObject = Dict[str, JsValue] @dataclass diff --git a/tests/async_resotoclient_test.py b/tests/async_resotoclient_test.py index 1def5e6..ee7177a 100644 --- a/tests/async_resotoclient_test.py +++ b/tests/async_resotoclient_test.py @@ -39,7 +39,7 @@ async def core_client() -> AsyncIterator[ResotoClient]: async def test_listen_to_events(core_client: ResotoClient) -> None: received: List[JsObject] = [] send_queue: Queue[JsObject] = Queue() - messages = [dict(kind="event", message_type="test", data={"foo": i}) for i in range(5)] + messages: List[JsObject] = [dict(kind="event", message_type="test", data={"foo": i}) for i in range(5)] for msg in messages: # add some messages that should be ignored - we are only listening for test events await send_queue.put(dict(kind="event", message_type="ignore_me")) diff --git a/tests/model_test.py b/tests/model_test.py index 6fcc720..7192fac 100644 --- a/tests/model_test.py +++ b/tests/model_test.py @@ -1,5 +1,17 @@ +from typing import Any + +import jsons + from resotoclient.json_utils import json_dump, json_load -from resotoclient.models import Property, Kind +from resotoclient.models import Property, Kind, JsValue + + +def __identity(obj: JsValue, *args: Any, **kwargs: Any) -> JsValue: + return obj + + +jsons.set_serializer(__identity, JsValue) # type: ignore +jsons.set_deserializer(__identity, JsValue) # type: ignore def test_prop_js_roundtrip() -> None: