From 470fb667bdf203a7704866e2d3458d010091b335 Mon Sep 17 00:00:00 2001 From: "Mike A." Date: Tue, 3 Sep 2024 18:19:02 +0200 Subject: [PATCH] fix: Pass pre-commit checks --- findmy/util/http.py | 19 +++++++++++++++---- pyproject.toml | 5 +++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/findmy/util/http.py b/findmy/util/http.py index c68ee7f..027694f 100644 --- a/findmy/util/http.py +++ b/findmy/util/http.py @@ -4,7 +4,7 @@ import json import logging -from typing import Any, TypedDict +from typing import Any, TypedDict, cast from aiohttp import BasicAuth, ClientSession, ClientTimeout from typing_extensions import Unpack, override @@ -15,13 +15,20 @@ logging.getLogger(__name__) -class _HttpRequestOptions(TypedDict, total=False): +class _RequestOptions(TypedDict, total=False): json: dict[str, Any] | None headers: dict[str, str] - auth: tuple[str, str] | BasicAuth data: bytes +class _AiohttpRequestOptions(_RequestOptions): + auth: BasicAuth + + +class _HttpRequestOptions(_RequestOptions, total=False): + auth: BasicAuth | tuple[str, str] + + class HttpResponse: """Response of a request made by `HttpSession`.""" @@ -95,15 +102,19 @@ async def request( """ session = await self._get_session() + # cast from http options to library supported options auth = kwargs.get("auth") if isinstance(auth, tuple): kwargs["auth"] = BasicAuth(auth[0], auth[1]) + else: + kwargs.pop("auth") + options = cast(_AiohttpRequestOptions, kwargs) async with await session.request( method, url, ssl=False, - **kwargs, + **options, ) as r: return HttpResponse(r.status, await r.content.read()) diff --git a/pyproject.toml b/pyproject.toml index fa56134..87edb04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,11 @@ venv = ".venv" typeCheckingMode = "standard" reportImplicitOverride = true +# examples should be run from their own directory +executionEnvironments = [ + { root = "examples/" } +] + [tool.ruff] line-length = 100