Skip to content

PYTHON-6026 Consolidate non-IO code in Async*ChangeStream/*ChangeStre… - #3105

Merged
sleepyStick merged 4 commits into
mongodb:mainfrom
sleepyStick:PYTHON-6026
Oct 9, 2026
Merged

sleepyStick merged 4 commits into
mongodb:mainfrom
sleepyStick:PYTHON-6026

Conversation

@sleepyStick

Copy link
Copy Markdown
Contributor

…am into shared base class

PYTHON-6026

Changes in this PR

Test Plan

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 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.61538% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pymongo/change_stream_shared.py 93.51% 5 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

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 refactor preserves existing behavior, and the multiple-inheritance dispatch correctly retains cluster-specific options.

0 open findings

What changed in this PR

Consolidates synchronous and asynchronous change-stream logic into a shared internal base while preserving API-specific I/O behavior.

Changes:

  • Moves validation, resume handling, and option construction into shared classes.
  • Adds shared sync/async database typings.
  • Includes inherited members in generated API documentation.
File Description
pymongo/​change_stream_shared.py Adds shared non-I/O change-stream implementation.
pymongo/​asynchronous/​change_stream.py Adopts shared bases for asynchronous streams.
pymongo/​synchronous/​change_stream.py Mirrors shared-base adoption for synchronous streams.
pymongo/​typings.py Adds agnostic database typing support.
doc/​api/​pymongo/​change_stream.rst Documents inherited synchronous members.
doc/​api/​pymongo/​asynchronous/​change_stream.rst Documents inherited asynchronous members.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

@sleepyStick
sleepyStick marked this pull request as ready for review October 8, 2026 16:34
@sleepyStick
sleepyStick requested a review from a team as a code owner October 8, 2026 16:34
Comment thread pymongo/change_stream_shared.py Outdated
"""Does this cursor have the potential to return more data?

.. note:: Even if :attr:`alive` is ``True``, :meth:`next` can raise
:exc:`StopIteration` and :meth:`try_next` can return ``None``.

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.

This is only accurate for async

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.

good catch, fixed in 1934b40

Comment thread pymongo/change_stream_shared.py Outdated
Comment on lines +59 to +68
"""The internal abstract base class for change stream cursors.

Should not be called directly by application developers. Use
:meth:`pymongo.collection.Collection.watch`,
:meth:`pymongo.database.Database.watch`, or
:meth:`pymongo.mongo_client.MongoClient.watch` instead.

.. versionadded:: 3.6
.. seealso:: The MongoDB documentation on `changeStreams <https://mongodb.com/docs/manual/changeStreams/>`_.
"""

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.

Since this is now private maybe just

"""
Shared base for the sync and async ChangeStream classes.
"""

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.

makes sense, done in 1934b40

self._closed = False
self._timeout = self._target._timeout
self._show_expanded_events = show_expanded_events

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.

Maybe a comment here about Any:

 # Any: the async and sync _AggregationCommand classes are not related by
  # inheritance, so no single return type is valid for both drivers.

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 modified your suggested comment to be more concise but otherwise added in 1934b40

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

LGTM!

@sleepyStick
sleepyStick merged commit 003ee6b into mongodb:main Oct 9, 2026
81 of 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