From 8dd8b535a72b886a957934bc95f95d085b4122a9 Mon Sep 17 00:00:00 2001 From: hnbdgr379 Date: Fri, 20 Dec 2024 13:37:49 +0100 Subject: [PATCH] Resolve unsoundness caught by pytype --strict-none-binding. (#3250) * Resolve unsoundness caught by pytype --strict-none-binding. --- .../python/timesketch_api_client/aggregation.py | 5 ++++- api_client/python/timesketch_api_client/client.py | 13 ++++++++++--- api_client/python/timesketch_api_client/graph.py | 6 ++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/api_client/python/timesketch_api_client/aggregation.py b/api_client/python/timesketch_api_client/aggregation.py index a64d6e7bfb..dbcd9db8d6 100644 --- a/api_client/python/timesketch_api_client/aggregation.py +++ b/api_client/python/timesketch_api_client/aggregation.py @@ -16,6 +16,7 @@ import getpass import json import logging +from typing import Any import altair import pandas @@ -41,6 +42,8 @@ class Aggregation(resource.SketchResource): saved search. """ + resource_data: dict[str, Any] + def __init__(self, sketch): self._created_at = "" self._name = "" @@ -307,7 +310,7 @@ def description(self, description): """Set the description of an aggregation.""" if "meta" not in self.resource_data: return - meta = self.resource_data.get("meta") + meta = self.resource_data.get("meta", {}) meta["description"] = description @property diff --git a/api_client/python/timesketch_api_client/client.py b/api_client/python/timesketch_api_client/client.py index e9f13eee8e..d25da7b0c7 100644 --- a/api_client/python/timesketch_api_client/client.py +++ b/api_client/python/timesketch_api_client/client.py @@ -106,11 +106,11 @@ def __init__( self._flow = None if not create_session: - self.session = None + self._session = None return try: - self.session = self._create_session( + self._session = self._create_session( username, password, verify=verify, @@ -145,13 +145,20 @@ def version(self): return "API Client: {0:s}".format(version.get_version()) + @property + def session(self): + """Property that returns the session object.""" + if self._session is None: + raise ValueError("Session is not set.") + return self._session + def set_credentials(self, credential_object): """Sets the credential object.""" self.credentials = credential_object def set_session(self, session_object): """Sets the session object.""" - self.session = session_object + self._session = session_object def _authenticate_session(self, session, username, password): """Post username/password to authenticate the HTTP session. diff --git a/api_client/python/timesketch_api_client/graph.py b/api_client/python/timesketch_api_client/graph.py index 4dd2e395c1..a0addeaef5 100644 --- a/api_client/python/timesketch_api_client/graph.py +++ b/api_client/python/timesketch_api_client/graph.py @@ -231,12 +231,14 @@ def from_graph(self, graph_obj): self._created_at = time self._updated_at = time - def from_manual(self, data, **kwargs): # pylint: disable=arguments-differ + def from_manual( + self, data, **kwargs + ): # pylint: disable=arguments-differ; pytype: disable=signature-mismatch """Generate a new graph using a dictionary. Args: data (dict): A dictionary of dictionaries adjacency representation. - kwargs (dict[str, object]): Depending on the resource they may + **kwargs (dict[str, object]): Depending on the resource they may require different sets of arguments to be able to run a raw API request.