From bc281cebea0ec1131a6fdf30a5501dde84a90477 Mon Sep 17 00:00:00 2001 From: frankgoldfish Date: Tue, 17 Mar 2026 18:01:07 -0700 Subject: [PATCH] fix: add aclose() alias to AsyncStream for async cleanup protocol support AsyncStream had a close() method but lacked aclose(), which is the standard async cleanup method expected by asyncio, contextlib.aclosing(), httpx, anyio, and instrumentation libraries. This adds aclose() as an alias for close() so AsyncStream integrates seamlessly with async resource management patterns. Co-Authored-By: Claude Sonnet 4.6 --- src/openai/_streaming.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/openai/_streaming.py b/src/openai/_streaming.py index 45c13cc11d..684e0dd505 100644 --- a/src/openai/_streaming.py +++ b/src/openai/_streaming.py @@ -238,6 +238,15 @@ async def close(self) -> None: """ await self.response.aclose() + async def aclose(self) -> None: + """ + Alias for close() to support the standard Python async cleanup protocol. + + This allows AsyncStream to be used with asyncio utilities and libraries + that expect an aclose() method (e.g. contextlib.aclosing, httpx, anyio). + """ + await self.close() + class ServerSentEvent: def __init__(