From 5bf3c8d20303b10544bd51e03345ae65cc5071a0 Mon Sep 17 00:00:00 2001 From: Mark Paronyan Date: Mon, 28 Sep 2026 05:09:43 +0000 Subject: [PATCH] fix(typing): resolve mypy errors in utils.http_client --- gns3server/utils/http_client.py | 17 ++++++++++++----- pyproject.toml | 1 - 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gns3server/utils/http_client.py b/gns3server/utils/http_client.py index 505073cf5..a6b032a82 100644 --- a/gns3server/utils/http_client.py +++ b/gns3server/utils/http_client.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import aiohttp +from pydantic import SecretStr import socket import logging @@ -28,7 +29,7 @@ class HTTPClient: HTTP client for request to computes and external services. """ - _aiohttp_client: aiohttp.ClientSession = None + _aiohttp_client: aiohttp.ClientSession | None = None @classmethod def get_client(cls, ssl_context=None) -> aiohttp.ClientSession: @@ -44,15 +45,21 @@ class HTTPClient: cls._aiohttp_client = None @classmethod - def request(cls, method: str, url: str, user: str = None, password: str = None, ssl_context=None, **kwargs): + def request( + cls, + method: str, + url: str, + user: str | None = None, + password: SecretStr | None = None, + ssl_context=None, + **kwargs, + ): client = cls.get_client(ssl_context=ssl_context) basic_auth = None if user: - if not password: - password = "" try: - basic_auth = aiohttp.BasicAuth(user, password.get_secret_value(), "utf-8") + basic_auth = aiohttp.BasicAuth(user, password.get_secret_value() if password else "", "utf-8") except ValueError as e: log.error(f"Basic authentication set-up error: {e}") diff --git a/pyproject.toml b/pyproject.toml index 258447eb6..53da2cea5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -399,7 +399,6 @@ module = [ "gns3server.services.templates", # 18 "gns3server.utils.asyncio.aiozipstream", # 8 "gns3server.utils.encryption", # 2 - "gns3server.utils.http_client", # 4 "gns3server.utils.images", # 4 "gns3server.utils.packet_filter_validation", # 16 "gns3server.utils.websocket_to_websocket", # 12