Skip to content

Commit 4fba492

Browse files
committed
[Authlib] Fix AsyncOAuth2Client missing async context manager methods.
1 parent bbddfee commit 4fba492

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

stubs/Authlib/@tests/stubtest_allowlist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ authlib.integrations.django_oauth2.*
5555
authlib.integrations.flask_client.*
5656
authlib.integrations.flask_oauth1.*
5757
authlib.integrations.flask_oauth2.*
58-
authlib.integrations.httpx_client.*
5958
authlib.integrations.requests_client.*
6059
authlib.integrations.sqla_oauth2.*
6160
authlib.integrations.starlette_client.*
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from __future__ import annotations
2+
3+
from authlib.integrations.httpx_client import AsyncOAuth2Client
4+
5+
6+
# ================================================================================
7+
# Test for AsyncOAuth2Client contex manager being correctly inherited and present.
8+
# ================================================================================
9+
async def test_client_contex_manager() -> None:
10+
async with AsyncOAuth2Client():
11+
pass

stubs/Authlib/METADATA.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
version = "1.6.6"
22
upstream_repository = "https://github.com/lepture/authlib"
3-
requires = ["cryptography"]
3+
requires = ["cryptography", "httpx"]
4+
5+
[tool.stubtest]
6+
extras = ["httpx"]

stubs/Authlib/authlib/integrations/httpx_client/oauth2_client.pyi

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from _typeshed import Incomplete
22
from collections.abc import Generator
3+
from contextlib import _AsyncGeneratorContextManager
34
from typing import NoReturn
4-
from typing_extensions import TypeAlias
5+
from typing_extensions import Self, TypeAlias
56

7+
import httpx
68
from authlib.oauth2.auth import ClientAuth, TokenAuth
79
from authlib.oauth2.client import OAuth2Client as _OAuth2Client
810

@@ -24,7 +26,7 @@ class OAuth2ClientAuth(ClientAuth):
2426
def auth_flow(self, request: _Request) -> Generator[_Request, _Response, None]: ...
2527

2628
# Inherits from httpx.AsyncClient
27-
class AsyncOAuth2Client(_OAuth2Client):
29+
class AsyncOAuth2Client(_OAuth2Client, httpx.AsyncClient):
2830
SESSION_REQUEST_PARAMS: list[str]
2931
client_auth_class = OAuth2ClientAuth
3032
token_auth_class = OAuth2Auth
@@ -43,8 +45,11 @@ class AsyncOAuth2Client(_OAuth2Client):
4345
leeway=60,
4446
**kwargs,
4547
) -> None: ...
48+
async def __aenter__(self) -> Self: ...
4649
async def request(self, method, url, withhold_token: bool = False, auth=..., **kwargs): ...
47-
async def stream(self, method, url, withhold_token: bool = False, auth=..., **kwargs) -> Generator[Incomplete]: ...
50+
def stream(
51+
self, method, url, withhold_token: bool = False, auth=..., **kwargs
52+
) -> _AsyncGeneratorContextManager[httpx.Response]: ...
4853
async def ensure_active_token(self, token): ... # type: ignore[override]
4954

5055
# Inherits from httpx.Client

0 commit comments

Comments
 (0)