From e380eda03a92febef8dae5fd1547ce9795d1326d Mon Sep 17 00:00:00 2001 From: Miwory Date: Sun, 26 Oct 2025 14:19:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D1=8B=20st?= =?UTF-8?q?ubs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- stubs/aiohttpx/__init__.pyi | 1 + stubs/aiohttpx/client.pyi | 33 ++++++++++++++++++++++ stubs/aiohttpx/responses/__init__.pyi | 6 ++++ stubs/aiohttpx/transports/__init__.pyi | 0 stubs/aiohttpx/transports/aio.pyi | 31 ++++++++++++++++++++ stubs/aiohttpx/transports/cache.pyi | 26 +++++++++++++++++ stubs/aiohttpx/transports/rate_limiter.pyi | 12 ++++++++ 8 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 stubs/aiohttpx/__init__.pyi create mode 100644 stubs/aiohttpx/client.pyi create mode 100644 stubs/aiohttpx/responses/__init__.pyi create mode 100644 stubs/aiohttpx/transports/__init__.pyi create mode 100644 stubs/aiohttpx/transports/aio.pyi create mode 100644 stubs/aiohttpx/transports/cache.pyi create mode 100644 stubs/aiohttpx/transports/rate_limiter.pyi diff --git a/pyproject.toml b/pyproject.toml index 164cde0..507f488 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ aiohttpx = "aiohttpx:main" [project.optional-dependencies] dev = [ "ruff==0.14.2", - "pyright==1.1.406", + "pyright==1.1.407", "poethepoet==0.37.0", "pre-commit==4.3.0", "types-redis==4.6.0.20241004", diff --git a/stubs/aiohttpx/__init__.pyi b/stubs/aiohttpx/__init__.pyi new file mode 100644 index 0000000..8e393b4 --- /dev/null +++ b/stubs/aiohttpx/__init__.pyi @@ -0,0 +1 @@ +__version__: str = ... diff --git a/stubs/aiohttpx/client.pyi b/stubs/aiohttpx/client.pyi new file mode 100644 index 0000000..e27767f --- /dev/null +++ b/stubs/aiohttpx/client.pyi @@ -0,0 +1,33 @@ +from collections.abc import Callable, Mapping +from ssl import SSLContext +from typing import Any + +from httpx import URL, Limits +from httpx import AsyncClient as AsyncHTTPXClient +from httpx import _types as t # type: ignore + +class AioHTTPXClient(AsyncHTTPXClient): + def __init__( + self, + *, + auth: t.AuthTypes | None = ..., + params: t.QueryParamTypes | None = ..., + headers: t.HeaderTypes | None = ..., + cookies: t.CookieTypes | None = ..., + verify: SSLContext | str | bool = ..., + cert: t.CertTypes | None = ..., + proxy: t.ProxyTypes | None = ..., + timeout: t.TimeoutTypes = ..., + follow_redirects: bool = ..., + limits: Limits = ..., + max_redirects: int = ..., + event_hooks: Mapping[str, list[Callable[..., Any]]] | None = ..., + base_url: URL | str = ..., + trust_env: bool = ..., + default_encoding: str | Callable[[bytes], str] = ..., + redis_url: str | None = ..., + key: str | None = ..., + limit: int | None = ..., + ) -> None: ... + +__all__ = ['AioHTTPXClient'] diff --git a/stubs/aiohttpx/responses/__init__.pyi b/stubs/aiohttpx/responses/__init__.pyi new file mode 100644 index 0000000..3b4e625 --- /dev/null +++ b/stubs/aiohttpx/responses/__init__.pyi @@ -0,0 +1,6 @@ +from typing import Any + +from httpx import Response as HTTPXResponse + +class Response(HTTPXResponse): + def json(self, **kwargs: Any) -> Any: ... diff --git a/stubs/aiohttpx/transports/__init__.pyi b/stubs/aiohttpx/transports/__init__.pyi new file mode 100644 index 0000000..e69de29 diff --git a/stubs/aiohttpx/transports/aio.pyi b/stubs/aiohttpx/transports/aio.pyi new file mode 100644 index 0000000..bce6c12 --- /dev/null +++ b/stubs/aiohttpx/transports/aio.pyi @@ -0,0 +1,31 @@ +from types import TracebackType +from typing import Any, Self + +import aiohttp +import httpx + +from aiohttpx.responses import Response + +EXCEPTIONS = ... + +class AiohttpTransport(httpx.AsyncBaseTransport): + def __init__( + self, session: aiohttp.ClientSession | None = ... + ) -> None: ... + def map_aiohttp_exception( + self, exc: Exception + ) -> httpx.TimeoutException | httpx.HTTPError: ... + async def __aenter__(self) -> Self: ... + async def __aexit__( + self, + exc_type: type[BaseException] | None = ..., + exc_value: BaseException | None = ..., + traceback: TracebackType | None = ..., + ) -> None: ... + async def aclose(self) -> None: ... + async def handle_async_request( + self, request: httpx.Request + ) -> Response: ... + async def make_request( + self, method: str, url: str, headers: dict[str, Any], data: bytes + ) -> Response: ... diff --git a/stubs/aiohttpx/transports/cache.pyi b/stubs/aiohttpx/transports/cache.pyi new file mode 100644 index 0000000..dfeaf36 --- /dev/null +++ b/stubs/aiohttpx/transports/cache.pyi @@ -0,0 +1,26 @@ +from httpx import Request +from httpx import Response as HTTPXResponse +from httpx import _models as m # type: ignore + +from aiohttpx.responses import Response +from aiohttpx.transports.rate_limiter import AsyncRateLimit, Redis + +def generate_cache_key(request: Request) -> str: ... +def cache_response( + client: Redis[bytes], + cache_key: str, + request: Request, + response: Response | HTTPXResponse, +) -> None: ... +def get_ttl_from_headers(headers: m.Headers) -> int | None: ... +def get_cached_response( + client: Redis[bytes], cache_key: str +) -> Response | None: ... +def serialize_response(response: Response | HTTPXResponse) -> bytes: ... +def deserialize_response(serialized_response: bytes) -> Response: ... + +class AsyncCacheTransport(AsyncRateLimit): + def __init__( + self, redis_url: str | None, key: str | None, limit: int | None + ) -> None: ... + async def handle_async_request(self, request: Request) -> Response: ... diff --git a/stubs/aiohttpx/transports/rate_limiter.pyi b/stubs/aiohttpx/transports/rate_limiter.pyi new file mode 100644 index 0000000..0b77a9f --- /dev/null +++ b/stubs/aiohttpx/transports/rate_limiter.pyi @@ -0,0 +1,12 @@ +from httpx import Request +from redis import Redis + +from aiohttpx.responses import Response +from aiohttpx.transports.aio import AiohttpTransport + +class AsyncRateLimit(AiohttpTransport): + def __init__( + self, redis: Redis[bytes] | None, key: str | None, limit: int | None + ) -> None: ... + async def request_is_limited(self) -> bool: ... + async def handle_async_request(self, request: Request) -> Response: ...