Skip to content

PYTHON-6029 Consolidate non-IO code in Pool and Connection into shared base class - #3129

Merged
NoahStapp merged 1 commit into
mongodb:mainfrom
NoahStapp:PYTHON-6029
Oct 16, 2026
Merged

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

Conversation

@NoahStapp

Copy link
Copy Markdown
Contributor

PYTHON-6029

Changes in this PR

See ticket.

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?

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.58120% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pymongo/pool_shared.py 96.15% 2 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

Comment thread pymongo/pool_shared.py
self.last_timeout = timeout
self.conn.get_conn.settimeout(timeout)

def apply_timeout(self, cmd: Optional[MutableMapping[str, Any]]) -> Optional[float]:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've removed the unused client parameter to avoid additional type complexity with the consolidation, but it does mean this PR has changes across usages. I could see instead moving that removal to a follow-up PR, but that leaves the codebase in an intermediate state where we have known dead code in-between.

@NoahStapp
NoahStapp marked this pull request as ready for review October 15, 2026 17:14
@NoahStapp
NoahStapp requested a review from a team as a code owner October 15, 2026 17:14
@NoahStapp
NoahStapp requested review from aclark4life and a balanced review from Copilot October 15, 2026 17:14

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

Static review identified no blocking regressions in the extraction or updated callers; tests were not run.

0 open findings

What changed in this PR

Consolidates shared, non-I/O pool and connection logic to reduce duplication between PyMongo’s synchronous and asynchronous drivers.

Changes:

  • Extracts common state and methods into generic base classes.
  • Removes the unused client argument from apply_timeout and updates callers.
  • Moves the telemetry protocol import under TYPE_CHECKING.
File Description
pymongo/​synchronous/​pool.py Uses shared base classes.
pymongo/​synchronous/​command_runner.py Updates timeout call.
pymongo/​synchronous/​client_bulk.py Updates client bulk timeout call.
pymongo/​synchronous/​bulk.py Updates collection bulk timeout call.
pymongo/​pool_shared.py Adds common pool and connection implementations.
pymongo/​message.py Updates shared calls and removes obsolete type ignores.
pymongo/​asynchronous/​pool.py Uses shared base classes.
pymongo/​asynchronous/​command_runner.py Updates timeout call.
pymongo/​asynchronous/​client_bulk.py Updates client bulk timeout call.
pymongo/​asynchronous/​bulk.py Updates collection bulk timeout call.
pymongo/​_telemetry.py Makes protocol import type-checking-only.

🧠 Review effort: Balanced


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

@aclark4life aclark4life 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.

Probably fine to remove unused client parameter, LGTM

@NoahStapp
NoahStapp merged commit b9ebe54 into mongodb:main Oct 16, 2026
93 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