Repository navigation
PYTHON-6028 Consolidate non-IO code in _ClientConnectionRetryable into shared base class - #3173
sleepyStick wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The retry helper subclass lacks __slots__ = (), introducing an instance dictionary and avoidable per-operation memory overhead despite its slotted base.
1 open issue
What changed in this PR
This PR consolidates non-I/O retry logic into a shared base class used by PyMongo’s asynchronous and synchronous clients.
Changes:
- Moves retry-state initialization, eligibility checks, last-error handling, and retry logging into
_AgnosticClientConnectionRetryableBase. - Updates both client helpers to inherit shared behavior while retaining their I/O-specific implementations.
| File | Description |
|---|---|
pymongo/synchronous/mongo_client.py |
Updates the generated synchronous helper to inherit the shared base. |
pymongo/mongo_client_shared.py |
Adds the generic base class containing common retry state and logic. |
pymongo/asynchronous/mongo_client.py |
Replaces duplicated non-I/O logic with inheritance from the shared base. |
Review effort: Balanced
| from pymongo.typings import ( | ||
| _Address, | ||
| _AgnosticBulk, | ||
| _AgnosticClientBulk, | ||
| _AgnosticClientSession, | ||
| _AgnosticMongoClient, | ||
| _AgnosticServer, |
There was a problem hiding this comment.
These should all be under if TYPE_CHECKING since they're used purely for type hints.
|
|
||
| class _ClientConnectionRetryable(Generic[T]): | ||
| class _ClientConnectionRetryable( | ||
| _AgnosticClientConnectionRetryableBase[T, "Server", _WriteCall[T] | _ReadCall[T]], Generic[T] |
There was a problem hiding this comment.
I don't think we need Generic[T] here since the parent class is already Generic[T].
There was a problem hiding this comment.
Intentional to include these changes here?
There was a problem hiding this comment.
🤦 that was entirely accidental 😭
should be gone now!!

PYTHON-6028
Changes in this PR
Test Plan
Checklist
Checklist for Author
Checklist for Reviewer