Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions httpcore/_backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,8 @@ async def connect_unix_socket(
) -> AsyncNetworkStream:
raise NotImplementedError() # pragma: nocover

async def aclose(self) -> None:
raise NotImplementedError() # pragma: nocover
Comment on lines +100 to +101
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change creates an asymmetry in the API design. The synchronous NetworkBackend class (line 36) does not have a close method, but now AsyncNetworkBackend has an aclose method. This inconsistency may be confusing for users and library maintainers.

Consider whether:

  1. NetworkBackend should also have a close method for consistency
  2. Or if neither backend type needs lifecycle management methods since they are typically stateless factories

Note that both NetworkStream (line 21) and AsyncNetworkStream (line 66) have close/aclose methods respectively, so the current pattern is that streams (connections) need cleanup but backends (connection factories) do not.

Copilot uses AI. Check for mistakes.

Comment on lines +100 to +102
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this method to the AsyncNetworkBackend interface creates a breaking change for type checkers. None of the existing implementations (AnyIOBackend, TrioBackend, AutoBackend, AsyncMockBackend) have implemented this method, which means:

  1. Type checkers will report that these implementations are missing the required aclose method
  2. Test backends in tests/test_cancellations.py (SlowWriteBackend, SlowReadBackend) will also fail type checking

Additionally, there is no usage of backend.aclose() anywhere in the codebase (e.g., connection pools do not call aclose on their backends), which suggests this method may not be needed yet.

If the goal is to make backends closeable for type checking purposes, all implementations need to be updated in the same PR to include either a working implementation or a no-op pass statement. The AutoBackend implementation in particular would need to delegate to self._backend.aclose() if that backend exists.

Suggested change
async def aclose(self) -> None:
raise NotImplementedError() # pragma: nocover

Copilot uses AI. Check for mistakes.
async def sleep(self, seconds: float) -> None:
raise NotImplementedError() # pragma: nocover
Loading