Skip to content

Commit

Permalink
fix: Pass pre-commit checks
Browse files Browse the repository at this point in the history
  • Loading branch information
malmeloo committed Sep 3, 2024
1 parent 1c18519 commit 470fb66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
19 changes: 15 additions & 4 deletions findmy/util/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`."""

Expand Down Expand Up @@ -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())

Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 470fb66

Please sign in to comment.