Skip to content

PYTHON-6260 Opt into all ruff TC rules - #3216

Merged
NoahStapp merged 2 commits into
mongodb:mainfrom
NoahStapp:PYTHON-6260
Nov 12, 2026
Merged

NoahStapp merged 2 commits into
mongodb:mainfrom
NoahStapp:PYTHON-6260

Conversation

@NoahStapp

Copy link
Copy Markdown
Contributor

PYTHON-6260

Changes in this PR

Enable all ruff TC linting rules and make the required code changes for them to pass.

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 12, 2026 15:24
@NoahStapp
NoahStapp requested review from aclark4life and a balanced review from Copilot November 12, 2026 15:24

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 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 TC001 and TC003 selections with TC.
  • Quote type arguments passed to cast() to avoid runtime type evaluation.
  • Move typing-only imports into TYPE_CHECKING blocks 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

Comment thread pyproject.toml Outdated
"ASYNC", # flake8-async
"TC001", # flake8-type-checking: typing-only first-party imports
"TC003", # flake8-type-checking: typing-only stdlib imports
"TC", # flake8-type-checking

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.

Missing a space or two here between "TC", and #

@NoahStapp
NoahStapp merged commit ccc82a2 into mongodb:main Nov 12, 2026
62 of 63 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