Repository navigation
PYTHON-6258 Enable ruff TC001 rule - #3211
Merged
Merged
Conversation
NoahStapp
requested review from
aclark4life
and
a balanced review from Copilot
November 11, 2026 19:30
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change enabling Ruff’s TC001 rule and moving typing-only imports out of runtime paths.
No open issues 🎉
What changed in this PR
Enables Ruff’s TC001 rule across PyMongo, BSON, GridFS, and their tests, moving typing-only first-party imports out of runtime import paths.
Changes:
- Enables
TC001in the Ruff configuration. - Moves annotation-only imports into
TYPE_CHECKINGblocks across asynchronous code and synchronous counterparts. - Adds targeted lint exemptions for retained runtime imports and updates the topology test’s
PoolOptionsimport.
| File | Description |
|---|---|
test/utils.py |
Guards client and pool type imports. |
test/unified_format.py |
Guards object ID and address type imports. |
test/unified_format_shared.py |
Guards server and topology description types. |
test/test_typing.py |
Moves Collection into the typing-only block. |
test/test_topology.py |
Imports PoolOptions from its defining module. |
test/test_sfp.py |
Guards the client type import. |
test/test_sdam_monitoring_spec.py |
Guards the collection type import. |
test/test_gridfs.py |
Guards the database type import. |
test/test_grid_file.py |
Guards the database type import. |
test/test_encryption.py |
Guards the collection type; removes Optional. |
test/test_cursor.py |
Guards the index-list type import. |
test/test_connections_survive_primary_stepdown_spec.py |
Guards the collection type import. |
test/test_collection.py |
Guards database and client type imports. |
test/test_client_metadata.py |
Guards the client type; removes Optional. |
test/test_bulk.py |
Guards collection and client types; removes Optional. |
test/mockupdb/test_cursor_namespace.py |
Guards the client type import. |
test/asynchronous/utils.py |
Guards async client and pool type imports. |
test/asynchronous/unified_format.py |
Guards object ID and address type imports. |
test/asynchronous/test_sfp.py |
Guards the async client type import. |
test/asynchronous/test_sdam_monitoring_spec.py |
Guards the async collection type import. |
test/asynchronous/test_gridfs.py |
Guards the async database type import. |
test/asynchronous/test_grid_file.py |
Guards the async database type import. |
test/asynchronous/test_encryption.py |
Guards the async collection type; removes Optional. |
test/asynchronous/test_cursor.py |
Guards the index-list type import. |
test/asynchronous/test_connections_survive_primary_stepdown_spec.py |
Guards the async collection type import. |
test/asynchronous/test_collection.py |
Guards async database and client types. |
test/asynchronous/test_client_metadata.py |
Guards the async client type; removes Optional. |
test/asynchronous/test_bulk.py |
Guards async collection and client types; removes Optional. |
test/asynchronous/__init__.py |
Guards the async database type import. |
test/__init__.py |
Guards the database type import. |
pyproject.toml |
Enables Ruff’s TC001 rule. |
pymongo/uri_parser_shared.py |
Guards the address type import. |
pymongo/topology_description.py |
Guards object ID and address type imports. |
pymongo/synchronous/settings.py |
Guards topology settings’ annotation-only imports. |
pymongo/synchronous/pool.py |
Exempts the backward-compatible PoolOptions import. |
pymongo/synchronous/mongo_client.py |
Guards timestamp and bulk-result types. |
pymongo/synchronous/encryption.py |
Guards callback, result, and cursor types. |
pymongo/synchronous/database.py |
Guards the timestamp type import. |
pymongo/synchronous/collection.py |
Guards the timestamp type import. |
pymongo/synchronous/client_session.py |
Guards read concern and preference types. |
pymongo/synchronous/client_bulk.py |
Guards session and write concern types. |
pymongo/synchronous/bulk.py |
Guards the session type import. |
pymongo/synchronous/_kms_connect.py |
Guards the pool options type import. |
pymongo/server_description.py |
Guards object ID, cluster time, and address types. |
pymongo/pool_shared.py |
Guards authentication context and pool options types. |
pymongo/operations.py |
Guards the raw BSON document type import. |
pymongo/monitoring.py |
Guards object ID, address, and document types. |
pymongo/message.py |
Guards the event-listener type import. |
pymongo/hello.py |
Guards the object ID type import. |
pymongo/encryption_shared.py |
Guards the bulk-write result type import. |
pymongo/encryption_options.py |
Exempts the runtime KMSConnectContext import. |
pymongo/change_stream_shared.py |
Guards codec options and timestamp types. |
pymongo/asynchronous/settings.py |
Guards topology settings’ annotation-only imports. |
pymongo/asynchronous/pool.py |
Exempts the backward-compatible PoolOptions import. |
pymongo/asynchronous/mongo_client.py |
Guards timestamp and bulk-result types. |
pymongo/asynchronous/encryption.py |
Guards async callback, cursor, and result types. |
pymongo/asynchronous/database.py |
Guards the timestamp type import. |
pymongo/asynchronous/collection.py |
Guards the timestamp type import. |
pymongo/asynchronous/client_session.py |
Guards read concern and preference types. |
pymongo/asynchronous/client_bulk.py |
Guards async session and write concern types. |
pymongo/asynchronous/bulk.py |
Guards the async session type import. |
pymongo/asynchronous/_kms_connect.py |
Guards the pool options type import. |
pymongo/_client_bulk_shared.py |
Guards the write concern type import. |
gridfs/synchronous/grid_file.py |
Guards the session type import. |
gridfs/asynchronous/grid_file.py |
Guards the async session type import. |
bson/codec_options.py |
Moves the document type import into TYPE_CHECKING. |
Review effort: Balanced
6 tasks
aclark4life
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-6258
Changes in this PR
Enable ruff's
TC001linting rule and make the required code changes for it to pass. Note that this and #3212 will have a ton of merge conflicts: I'll resolve them once the first of the two is merged.Test Plan
Existing test suite.
Checklist
Checklist for Author
Checklist for Reviewer