Repository navigation
PYTHON-6280 Enable non-design PLR ruff rules - #3232
Merged
Merged
Conversation
NoahStapp
requested review from
blink1073
and
a balanced review from Copilot
November 17, 2026 15:31
Contributor
There was a problem hiding this comment.
🟢 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
PLRrules 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
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-6280
Changes in this PR
Enable all ruff
PLRrules 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