Skip to content

PYTHON-6258 Enable ruff TC001 rule - #3211

Merged
NoahStapp merged 1 commit into
mongodb:mainfrom
NoahStapp:PYTHON-6258
Nov 11, 2026
Merged

NoahStapp merged 1 commit into
mongodb:mainfrom
NoahStapp:PYTHON-6258

Conversation

@NoahStapp

@NoahStapp NoahStapp commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

PYTHON-6258

Changes in this PR

Enable ruff's TC001 linting 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

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

@NoahStapp
NoahStapp requested a review from a team as a code owner November 11, 2026 19:30
@NoahStapp
NoahStapp requested review from aclark4life and a balanced review from Copilot November 11, 2026 19:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 TC001 in the Ruff configuration.
  • Moves annotation-only imports into TYPE_CHECKING blocks across asynchronous code and synchronous counterparts.
  • Adds targeted lint exemptions for retained runtime imports and updates the topology test’s PoolOptions import.
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

@NoahStapp
NoahStapp merged commit 44506bb into mongodb:main Nov 11, 2026
83 checks passed
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.

3 participants