Skip to content

uniformize context managers - #1755

Merged
aaugustin merged 2 commits into
mainfrom
uniformize-context-managers
Aug 29, 2026
Merged

uniformize context managers#1755
aaugustin merged 2 commits into
mainfrom
uniformize-context-managers

Conversation

@aaugustin

Copy link
Copy Markdown
Member
  • Simplify error handling in servers.
  • Make clients use close code 1011 on exceptions.

Rely on the connection's context manager implementation instead of
duplicating its logic.
According to errata 3227, which is approved, the meaning of code 1011
also applies to clients. It makes sense to use them symetrically.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Unifies modern client/server context-manager cleanup and applies close code 1011 when exiting after an exception.

Changes:

  • Delegates client context exit to connection implementations.
  • Simplifies server handler cleanup with connection context managers.
  • Adds normal and exceptional close-code tests across all runtimes.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/websockets/asyncio/client.py Delegates async context management.
src/websockets/asyncio/server.py Context-manages handler connections.
src/websockets/sync/client.py Delegates sync context management.
src/websockets/sync/server.py Context-manages handler connections.
src/websockets/trio/client.py Delegates context management while preserving nursery cleanup.
src/websockets/trio/server.py Context-manages handler connections.
tests/asyncio/test_client.py Tests close codes 1000 and 1011.
tests/sync/test_client.py Tests close codes 1000 and 1011.
tests/trio/test_client.py Tests close codes 1000 and 1011.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@aaugustin
aaugustin merged commit 544779c into main Aug 29, 2026
9 checks passed
@aaugustin
aaugustin deleted the uniformize-context-managers branch August 29, 2026 19:51
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.

2 participants