Skip to content

PYTHON-6280 Enable non-design PLR ruff rules - #3232

Merged
NoahStapp merged 1 commit into
mongodb:mainfrom
NoahStapp:PYTHON-6280
Nov 17, 2026
Merged

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

Conversation

@NoahStapp

Copy link
Copy Markdown
Contributor

PYTHON-6280

Changes in this PR

Enable all ruff PLR rules that are not design rules and make the required code changes to pass them: PLR0402, PLR1704, PLR1711, PLR1714, PLR1730, PLR1733, PLR5501, PLR0124, PLR0133, PLR0206, PLR1708, PLR1716, PLR1722, PLR1736, and PLR2044.

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 17, 2026 15:31
@NoahStapp
NoahStapp requested review from blink1073 and a balanced review from Copilot November 17, 2026 15:31

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 block the Ruff PLR rule enablement and associated code cleanup.

No open issues 🎉

What changed in this PR

This PR enables 15 non-design Ruff PLR rules and updates PyMongo’s driver, BSON code, and test suites to comply without intended behavior changes.

Changes:

  • Enables selected PLR rules while retaining the broader exclusion for design-related rules.
  • Simplifies comparisons and control flow, removes redundant returns, and standardizes imports.
  • Renames shadowed variables and carries matching changes into generated synchronous code.
File Description
test/​utils_shared.py Uses membership checks for operation arguments.
test/​unified_format.py Updates generated membership checks.
test/​unified_format_shared.py Flattens branches and reuses dictionary values.
test/​test_ssl.py Updates the generated mock import.
test/​test_ssl_support.py Standardizes the mock import.
test/​test_read_write_concern_spec.py Updates generated directory filtering.
test/​test_read_preferences.py Removes generated argument shadowing.
test/​test_kms_connect.py Removes a redundant return None.
test/​test_dns.py Updates generated option comparisons.
test/​test_discovery_and_monitoring.py Flattens generated monitor-state checks.
test/​test_auth_spec.py Flattens generated authentication assertions.
test/​asynchronous/​unified_format.py Uses membership checks for operation names.
test/​asynchronous/​test_ssl.py Standardizes the mock import.
test/​asynchronous/​test_read_write_concern_spec.py Simplifies directory filtering.
test/​asynchronous/​test_read_preferences.py Avoids shadowing the read-preference argument.
test/​asynchronous/​test_dns.py Simplifies option comparisons.
test/​asynchronous/​test_discovery_and_monitoring.py Flattens monitor-state checks.
test/​asynchronous/​test_auth_spec.py Flattens authentication assertions.
test/​asynchronous/​__init__.py Simplifies IPv6 configuration checks.
test/​__init__.py Updates generated IPv6 checks.
pyproject.toml Enables 15 non-design PLR rules.
pymongo/​synchronous/​pool.py Updates generated pool cleanup branches.
pymongo/​synchronous/​mongo_client.py Updates generated option filtering and write-concern branches.
pymongo/​pyopenssl_context.py Standardizes the x509 import.
pymongo/​pool_shared.py Avoids shadowing the service-ID argument.
pymongo/​network_layer.py Flattens receive-deadline selection.
pymongo/​common.py Simplifies validators and removes argument shadowing.
pymongo/​client_session_shared.py Uses max() to advance operation time.
pymongo/​asynchronous/​pool.py Flattens pool cleanup and connection-return branches.
pymongo/​asynchronous/​mongo_client.py Simplifies option filtering and write-concern inheritance.
pymongo/​_asyncio_lock.py Removes a redundant return.
bson/​datetime_ms.py Uses membership testing for conversion modes.
bson/​binary.py Flattens standard UUID decoding logic.

Review effort: Balanced

@blink1073 blink1073 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@NoahStapp
NoahStapp merged commit 29526b0 into mongodb:main Nov 17, 2026
81 of 82 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