Repository navigation
PYTHON-6260 Opt into all ruff TC rules - #3216
Merged
Merged
Conversation
NoahStapp
requested review from
aclark4life
and
a balanced review from Copilot
November 12, 2026 15:24
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the Ruff typing-rule and related import updates.
No open issues 🎉
What changed in this PR
This PR enables Ruff’s full TC rule family and updates typing-related code across PyMongo, BSON, GridFS, tests, and tooling to comply.
Changes:
- Replace individual
TC001andTC003selections withTC. - Quote type arguments passed to
cast()to avoid runtime type evaluation. - Move typing-only imports into
TYPE_CHECKINGblocks and mirror changes in generated synchronous code.
| File | Description |
|---|---|
tools/test_synchro.py |
Guard the typing-only pytest import. |
test/test_typing.py |
Quote the decorator’s cast type. |
test/test_ocsp_support.py |
Quote certificate-name cast types. |
test/test_client_metadata.py |
Mirror the metadata cast update. |
test/asynchronous/test_client_metadata.py |
Quote the version-string cast type. |
pyproject.toml |
Enable the full Ruff TC rule family. |
pymongo/uri_parser_shared.py |
Quote option-dictionary cast types. |
pymongo/topology_description.py |
Quote the round-trip-time cast type. |
pymongo/synchronous/topology.py |
Mirror the server cast update. |
pymongo/synchronous/mongo_client.py |
Mirror client cast updates. |
pymongo/synchronous/helpers.py |
Mirror the decorator cast update. |
pymongo/synchronous/encryption.py |
Mirror encryption casts and import guarding. |
pymongo/synchronous/database.py |
Mirror database casts and typing-only imports. |
pymongo/synchronous/cursor.py |
Mirror the response-list cast update. |
pymongo/synchronous/collection.py |
Mirror collection casts and typing-only imports. |
pymongo/synchronous/_kms_connect.py |
Mirror the port cast update. |
pymongo/socket_checker.py |
Quote error-number cast types. |
pymongo/server_selectors.py |
Quote the last-write-date cast type. |
pymongo/results.py |
Guard mapping imports and quote result casts. |
pymongo/mongo_client_shared.py |
Quote the error-details cast type. |
pymongo/cursor_shared.py |
Quote the query-dictionary cast type. |
pymongo/client_session_shared.py |
Quote the connection-manager cast type. |
pymongo/client_options.py |
Guard collection types and quote the listener cast. |
pymongo/auth_shared.py |
Quote authentication cast types. |
pymongo/asynchronous/topology.py |
Quote the selected-server cast type. |
pymongo/asynchronous/mongo_client.py |
Quote database-name and server-info cast types. |
pymongo/asynchronous/helpers.py |
Quote the decorator’s cast type. |
pymongo/asynchronous/encryption.py |
Guard the collection import and quote encryption casts. |
pymongo/asynchronous/database.py |
Guard collection types and quote database casts. |
pymongo/asynchronous/cursor.py |
Quote the complete response-list cast type. |
pymongo/asynchronous/collection.py |
Guard collection types and quote collection casts. |
pymongo/asynchronous/_kms_connect.py |
Quote the KMS port cast type. |
pymongo/_csot.py |
Quote the timeout-wrapper cast type. |
gridfs/synchronous/grid_file.py |
Mirror the upload-result cast update. |
gridfs/asynchronous/grid_file.py |
Quote the upload-result cast type. |
bson/json_util.py |
Quote JSON-options and UUID cast types. |
bson/datetime_ms.py |
Quote the datetime cast type. |
bson/codec_options.py |
Quote the type-codec cast type. |
bson/__init__.py |
Quote BSON decoding cast types. |
.evergreen/scripts/generate_config.py |
Guard the typing-only build-variant import. |
Review effort: Balanced
aclark4life
requested changes
Nov 12, 2026
| "ASYNC", # flake8-async | ||
| "TC001", # flake8-type-checking: typing-only first-party imports | ||
| "TC003", # flake8-type-checking: typing-only stdlib imports | ||
| "TC", # flake8-type-checking |
Contributor
There was a problem hiding this comment.
Missing a space or two here between "TC", and #
aclark4life
approved these changes
Nov 12, 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-6260
Changes in this PR
Enable all ruff
TClinting rules and make the required code changes for them to pass.Test Plan
Existing test suite.
Checklist
Checklist for Author
Checklist for Reviewer