Skip to content

Conversation

@NoahStapp
Copy link
Contributor

@NoahStapp NoahStapp commented Jan 29, 2026

[PYTHON-1357]

Changes in this PR

  • Refactor code shared between (Async)Cursor and (Async)CommandCursor into abstracted base classes.
  • _AgnosticCursorBase is the top-level base class that is IO-agnostic and shared between both async and sync cursor implementations.
  • _AsyncCursorBase and _CursorBase are async and sync-specific base classes that contain code shared between cursor implementations in either the async or sync APIs.
  • These changes must not introduce any user-facing changes.
  • Two type hints differ between Cursor and CommandCursor: Cursor.cursor_id -> Optional[int] and Cursor.address -> Optional[tuple[str, Any]], while CommandCursor.cursor_id -> int and CommandCursor.address -> Optional[_Address]. Do we count these type hint changes as user-facing, public API changes? Note that _Address = Tuple[str, Optional[int]].
  • This is a refactor of identical or nearly identical common code only. Some existing code such as _send_message is similar between the cursor types but has enough differences to be effectively separate implementations.

Test Plan

Run against the 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 marked this pull request as ready for review January 29, 2026 21:48
@NoahStapp NoahStapp requested a review from a team as a code owner January 29, 2026 21:48
@NoahStapp NoahStapp requested a review from Jibola January 29, 2026 21:48
from pymongo.typings import _Address, _DocumentType


class _AgnosticCursorBase(Generic[_DocumentType], ABC):
Copy link
Member

Choose a reason for hiding this comment

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

I think that this is the only class in the hierarchy that needs Generic[_DocumentType] explicitly spelled out

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.

2 participants