Skip to content

PYTHON-6158 Clean up version-gated code paths - #3112

Merged
aclark4life merged 2 commits into
mongodb:mainfrom
aclark4life:PYTHON-6158-clean-up-version-gated-code
Oct 10, 2026
Merged

aclark4life merged 2 commits into
mongodb:mainfrom
aclark4life:PYTHON-6158-clean-up-version-gated-code

Conversation

@aclark4life

@aclark4life aclark4life commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

PYTHON-6158

Changes in this PR

Follow-up to PYTHON-6138 (drop Python 3.9 and 3.10). Removes version-gated code paths that are now dead on Python 3.11+:

  • Delete pymongo/_asyncio_task.py, callers use asyncio.create_task.
  • Import Self from typing unconditionally in pymongo/cursor_shared.py.
  • Remove the Python 3.11 gate on async TLS session injection in pymongo/pool_shared.py.
  • Use zip(..., strict=True) unconditionally in pymongo/pool_options.py.
  • Remove the Python 3.9/3.10 anext/aiter fallbacks in pymongo/asynchronous/helpers.py.
  • Remove dead 3.10/3.11 gates in tests.

Test Plan

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is the intention of the code captured in relevant tests?
  • If there are new TODOs, has a related JIRA ticket been created?

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?)
  • Have you checked for spelling & grammar errors?
  • Is all relevant documentation (README or docstring) updated?

@aclark4life
aclark4life marked this pull request as ready for review October 9, 2026 16:35
@aclark4life
aclark4life requested a review from a team as a code owner October 9, 2026 16:35
@aclark4life
aclark4life requested review from sleepyStick and a balanced review from Copilot October 9, 2026 16:35

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

The removed branches only support now-unsupported Python versions, and the replacements preserve existing Python 3.11+ behavior.

0 open findings

What changed in this PR

Removes obsolete compatibility paths after raising the minimum supported Python version to 3.11.

Changes:

  • Replaces the custom task wrapper with asyncio.create_task.
  • Removes dead version checks and compatibility fallbacks.
  • Enables Python 3.11+ test paths unconditionally.
File Description
pymongo/​_asyncio_task.py Removes the obsolete task compatibility module.
pymongo/​asynchronous/​helpers.py Uses built-in anext and aiter.
pymongo/​synchronous/​helpers.py Uses built-in next and iter.
pymongo/​cursor_shared.py Imports Self directly from typing.
pymongo/​network_layer.py Uses asyncio.create_task directly.
pymongo/​periodic_executor.py Uses asyncio.create_task directly.
pymongo/​pool_options.py Uses strict zip unconditionally.
pymongo/​pool_shared.py Removes the TLS injection version gate.
test/​helpers.py Updates generated task creation.
test/​asynchronous/​helpers.py Updates asynchronous task creation.
test/​test_client.py Removes obsolete context-manager gating.
test/​asynchronous/​test_client.py Removes obsolete async context-manager gating.
test/​test_discovery_and_monitoring.py Removes the obsolete barrier skip.
test/​asynchronous/​test_discovery_and_monitoring.py Removes the obsolete barrier skip.
test/​test_encryption.py Accepts the modern TLS EOF error unconditionally.
test/​asynchronous/​test_encryption.py Accepts the modern TLS EOF error unconditionally.
test/​asynchronous/​test_locks.py Enables Python 3.11 asyncio tests unconditionally.
test/​test_retryable_writes.py Uses asyncio.create_task directly.
test/​asynchronous/​test_retryable_writes.py Uses asyncio.create_task directly.
test/​test_ssl.py Removes obsolete async TLS test gates.
test/​asynchronous/​test_ssl.py Removes obsolete async TLS test gates.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread test/asynchronous/test_encryption.py Outdated
Comment on lines 2060 to 2061
# This error might be:
# EOF occurred in violation of protocol (_ssl.c:2384)

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.

nit: can this be put onto the same line? or like can we fix the spacing here?

Comment thread pymongo/periodic_executor.py Outdated
@@ -67,7 +66,7 @@ def open(self) -> None:
if self._task is None or (
self._task.done() and not self._task.cancelled() and not self._task.cancelling() # type: ignore[unused-ignore, attr-defined]

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.

i could be wrong, but i think these type ignores can be removed here? (and on line 101)

- Remove obsolete type: ignore comments in periodic_executor.py
- Merge cert_error EOF pattern onto one line in test_encryption.py
@aclark4life
aclark4life merged commit 1f64ecd into mongodb:main Oct 10, 2026
81 of 93 checks passed
@aclark4life
aclark4life deleted the PYTHON-6158-clean-up-version-gated-code branch October 10, 2026 01:19
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