Skip to content

fix: add aclose() alias to AsyncStream#2982

Open
frankgoldfish wants to merge 1 commit intoopenai:mainfrom
frankgoldfish:fix/async-stream-aclose
Open

fix: add aclose() alias to AsyncStream#2982
frankgoldfish wants to merge 1 commit intoopenai:mainfrom
frankgoldfish:fix/async-stream-aclose

Conversation

@frankgoldfish
Copy link

Summary

  • AsyncStream had a close() method but was missing aclose(), which is the standard async resource cleanup method in Python
  • Adds aclose() as an alias for close() in AsyncStream to support the async cleanup protocol used by asyncio, contextlib.aclosing(), httpx, anyio, and instrumentation/tracing libraries
  • The sync Stream class already follows the context manager protocol correctly; this brings AsyncStream to parity for callers that rely on the conventional aclose() name

Test plan

  • Verify AsyncStream can be used with contextlib.aclosing(stream) in async contexts
  • Verify await stream.aclose() closes the underlying response (same as await stream.close())
  • Existing tests should continue to pass unchanged

🤖 Generated with Claude Code

…port

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 <noreply@anthropic.com>
@frankgoldfish frankgoldfish requested a review from a team as a code owner March 18, 2026 01:01
Jah-yee pushed a commit to Jah-yee/openai-python that referenced this pull request Mar 18, 2026
- Add aclose() as an alias for close() in AsyncStream
- Supports standard async resource cleanup protocol used by
  asyncio, contextlib.aclosing(), httpx, anyio, and instrumentation
- Brings AsyncStream to parity with callers that rely on conventional
  aclose() name

Fixes openai#2982
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant