Repository navigation
PYTHON-6244 Enable ruff TRY rules - #3204
Merged
Merged
Conversation
NoahStapp
requested review from
sleepyStick
and
a balanced review from Copilot
November 11, 2026 16:38
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Exception changes from ValueError to TypeError leave existing session, server-selector, and OIDC test assertions incompatible; update the asynchronous assertions and regenerate their synchronous counterparts.
3 open issues
What changed in this PR
Enables Ruff’s TRY rules and updates exception handling across the driver, tests, and development tools.
Changes:
- Removes the blanket
TRYexclusion and adds targeted suppressions. - Uses more specific exception types for validation and failure cases.
- Replaces explicit exception re-raises with bare
raisestatements.
| File | Description |
|---|---|
| tools/synchro.py | Uses a bare re-raise for missing sync markers. |
| tools/fail_if_no_c.py | Adds targeted exception-logging suppressions. |
| test/utils.py | Mirrors retry re-raise cleanup. |
| test/unified_format_shared.py | Uses ValueError for unsupported events. |
| test/test_sfp.py | Mirrors environment-validation exception changes. |
| test/test_load_balancer.py | Mirrors timeout exception changes. |
| test/test_examples.py | Mirrors the transaction-example suppression. |
| test/test_client.py | Mirrors the connection-failure exception change. |
| test/helpers.py | Mirrors the helper’s RuntimeError change. |
| test/atlas/test_connection.py | Uses ValueError for missing configuration. |
| test/asynchronous/utils.py | Uses a bare re-raise after exhausted retries. |
| test/asynchronous/test_sfp.py | Uses ValueError for missing environment variables. |
| test/asynchronous/test_load_balancer.py | Uses TimeoutError for unlock timeouts. |
| test/asynchronous/test_examples.py | Preserves illustrative error handling with a suppression. |
| test/asynchronous/test_client.py | Uses ConnectionFailure in the connection stub. |
| test/asynchronous/helpers.py | Uses RuntimeError for helper failures. |
| pyproject.toml | Enables Ruff’s TRY rules. |
| pymongo/synchronous/monitor.py | Mirrors monitor exception changes and suppression. |
| pymongo/synchronous/collection.py | Mirrors return-document validation changes. |
| pymongo/synchronous/auth_oidc.py | Mirrors callback-result validation changes. |
| pymongo/pyopenssl_context.py | Uses a bare re-raise for nonblocking I/O errors. |
| pymongo/common.py | Uses TypeError for invalid argument types. |
| pymongo/client_session_shared.py | Uses TypeError for invalid cluster time. |
| pymongo/asynchronous/monitor.py | Adds a specific SRV error and targeted suppression. |
| pymongo/asynchronous/collection.py | Uses TypeError for invalid return-document types. |
| pymongo/asynchronous/auth_oidc.py | Uses TypeError for invalid callback results. |
| bson/codec_options.py | Uses TypeError for invalid decode-handler types. |
Review effort: Balanced
NoahStapp
marked this pull request as draft
November 11, 2026 16:57
NoahStapp
force-pushed
the
PYTHON-6244
branch
from
November 11, 2026 18:30
1970b7d to
283afca
Compare
NoahStapp
marked this pull request as ready for review
November 11, 2026 19:25
sleepyStick
approved these changes
Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PYTHON-6244
Changes in this PR
Enable ruff's
TRYlinting rules and make the necessary code changes to have them pass.Test Plan
Existing test suite. Passing run of affected OIDC tests.
Checklist
Checklist for Author
Checklist for Reviewer