From 4fba492fca8a30419ff77eface129f05345262f2 Mon Sep 17 00:00:00 2001 From: robertuss12 <47995308+robertuss12@users.noreply.github.com> Date: Mon, 29 Dec 2025 11:32:26 +0100 Subject: [PATCH] [Authlib] Fix AsyncOAuth2Client missing async context manager methods. --- stubs/Authlib/@tests/stubtest_allowlist.txt | 1 - .../check_integration_httpx_client_oauth2.py | 11 +++++++++++ stubs/Authlib/METADATA.toml | 5 ++++- .../integrations/httpx_client/oauth2_client.pyi | 11 ++++++++--- 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 stubs/Authlib/@tests/test_cases/check_integration_httpx_client_oauth2.py diff --git a/stubs/Authlib/@tests/stubtest_allowlist.txt b/stubs/Authlib/@tests/stubtest_allowlist.txt index f6fa5a1738fa..a4591cfce178 100644 --- a/stubs/Authlib/@tests/stubtest_allowlist.txt +++ b/stubs/Authlib/@tests/stubtest_allowlist.txt @@ -55,7 +55,6 @@ authlib.integrations.django_oauth2.* authlib.integrations.flask_client.* authlib.integrations.flask_oauth1.* authlib.integrations.flask_oauth2.* -authlib.integrations.httpx_client.* authlib.integrations.requests_client.* authlib.integrations.sqla_oauth2.* authlib.integrations.starlette_client.* diff --git a/stubs/Authlib/@tests/test_cases/check_integration_httpx_client_oauth2.py b/stubs/Authlib/@tests/test_cases/check_integration_httpx_client_oauth2.py new file mode 100644 index 000000000000..1ba02ecdb151 --- /dev/null +++ b/stubs/Authlib/@tests/test_cases/check_integration_httpx_client_oauth2.py @@ -0,0 +1,11 @@ +from __future__ import annotations + +from authlib.integrations.httpx_client import AsyncOAuth2Client + + +# ================================================================================ +# Test for AsyncOAuth2Client contex manager being correctly inherited and present. +# ================================================================================ +async def test_client_contex_manager() -> None: + async with AsyncOAuth2Client(): + pass diff --git a/stubs/Authlib/METADATA.toml b/stubs/Authlib/METADATA.toml index b8a8459de205..f4e179165953 100644 --- a/stubs/Authlib/METADATA.toml +++ b/stubs/Authlib/METADATA.toml @@ -1,3 +1,6 @@ version = "1.6.6" upstream_repository = "https://github.com/lepture/authlib" -requires = ["cryptography"] +requires = ["cryptography", "httpx"] + +[tool.stubtest] +extras = ["httpx"] diff --git a/stubs/Authlib/authlib/integrations/httpx_client/oauth2_client.pyi b/stubs/Authlib/authlib/integrations/httpx_client/oauth2_client.pyi index 79d45bd3c2af..2cbf674b473c 100644 --- a/stubs/Authlib/authlib/integrations/httpx_client/oauth2_client.pyi +++ b/stubs/Authlib/authlib/integrations/httpx_client/oauth2_client.pyi @@ -1,8 +1,10 @@ from _typeshed import Incomplete from collections.abc import Generator +from contextlib import _AsyncGeneratorContextManager from typing import NoReturn -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias +import httpx from authlib.oauth2.auth import ClientAuth, TokenAuth from authlib.oauth2.client import OAuth2Client as _OAuth2Client @@ -24,7 +26,7 @@ class OAuth2ClientAuth(ClientAuth): def auth_flow(self, request: _Request) -> Generator[_Request, _Response, None]: ... # Inherits from httpx.AsyncClient -class AsyncOAuth2Client(_OAuth2Client): +class AsyncOAuth2Client(_OAuth2Client, httpx.AsyncClient): SESSION_REQUEST_PARAMS: list[str] client_auth_class = OAuth2ClientAuth token_auth_class = OAuth2Auth @@ -43,8 +45,11 @@ class AsyncOAuth2Client(_OAuth2Client): leeway=60, **kwargs, ) -> None: ... + async def __aenter__(self) -> Self: ... async def request(self, method, url, withhold_token: bool = False, auth=..., **kwargs): ... - async def stream(self, method, url, withhold_token: bool = False, auth=..., **kwargs) -> Generator[Incomplete]: ... + def stream( + self, method, url, withhold_token: bool = False, auth=..., **kwargs + ) -> _AsyncGeneratorContextManager[httpx.Response]: ... async def ensure_active_token(self, token): ... # type: ignore[override] # Inherits from httpx.Client