Skip to content

Commit f7da117

Browse files
authored
PYTHON-4592 - Synchronize inline examples and docstrings (mongodb#1756)
1 parent 294f10b commit f7da117

18 files changed

+396
-385
lines changed

pymongo/asynchronous/aggregation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class _AggregationCommand:
4040
"""The internal abstract base class for aggregation cursors.
4141
4242
Should not be called directly by application developers. Use
43-
:meth:`pymongo.collection.AsyncCollection.aggregate`, or
44-
:meth:`pymongo.database.AsyncDatabase.aggregate` instead.
43+
:meth:`pymongo.asynchronous.collection.AsyncCollection.aggregate`, or
44+
:meth:`pymongo.asynchronous.database.AsyncDatabase.aggregate` instead.
4545
"""
4646

4747
def __init__(

pymongo/asynchronous/change_stream.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ class AsyncChangeStream(Generic[_DocumentType]):
9191
"""The internal abstract base class for change stream cursors.
9292
9393
Should not be called directly by application developers. Use
94-
:meth:`pymongo.collection.AsyncCollection.watch`,
95-
:meth:`pymongo.database.AsyncDatabase.watch`, or
96-
:meth:`pymongo.mongo_client.AsyncMongoClient.watch` instead.
94+
:meth:`pymongo.asynchronous.collection.AsyncCollection.watch`,
95+
:meth:`pymongo.asynchronous.database.AsyncDatabase.watch`, or
96+
:meth:`pymongo.asynchronous.mongo_client.AsyncMongoClient.watch` instead.
9797
9898
.. versionadded:: 3.6
9999
.. seealso:: The MongoDB documentation on `changeStreams <https://mongodb.com/docs/manual/changeStreams/>`_.
@@ -166,7 +166,7 @@ def _aggregation_command_class(self) -> Type[_AggregationCommand]:
166166
@property
167167
def _client(self) -> AsyncMongoClient:
168168
"""The client against which the aggregation commands for
169-
this ChangeStream will be run.
169+
this AsyncChangeStream will be run.
170170
"""
171171
raise NotImplementedError
172172

@@ -204,7 +204,7 @@ def _command_options(self) -> dict[str, Any]:
204204
return options
205205

206206
def _aggregation_pipeline(self) -> list[dict[str, Any]]:
207-
"""Return the full aggregation pipeline for this ChangeStream."""
207+
"""Return the full aggregation pipeline for this AsyncChangeStream."""
208208
options = self._change_stream_options()
209209
full_pipeline: list = [{"$changeStream": options}]
210210
full_pipeline.extend(self._pipeline)
@@ -238,7 +238,7 @@ def _process_result(self, result: Mapping[str, Any], conn: AsyncConnection) -> N
238238
async def _run_aggregation_cmd(
239239
self, session: Optional[AsyncClientSession], explicit_session: bool
240240
) -> AsyncCommandCursor:
241-
"""Run the full aggregation pipeline for this ChangeStream and return
241+
"""Run the full aggregation pipeline for this AsyncChangeStream and return
242242
the corresponding AsyncCommandCursor.
243243
"""
244244
cmd = self._aggregation_command_class(
@@ -272,7 +272,7 @@ async def _resume(self) -> None:
272272
self._cursor = await self._create_cursor()
273273

274274
async def close(self) -> None:
275-
"""Close this ChangeStream."""
275+
"""Close this AsyncChangeStream."""
276276
self._closed = True
277277
await self._cursor.close()
278278

@@ -299,27 +299,27 @@ async def next(self) -> _DocumentType:
299299
try:
300300
resume_token = None
301301
pipeline = [{'$match': {'operationType': 'insert'}}]
302-
async with db.collection.watch(pipeline) as stream:
302+
async with await db.collection.watch(pipeline) as stream:
303303
async for insert_change in stream:
304304
print(insert_change)
305305
resume_token = stream.resume_token
306306
except pymongo.errors.PyMongoError:
307-
# The ChangeStream encountered an unrecoverable error or the
307+
# The AsyncChangeStream encountered an unrecoverable error or the
308308
# resume attempt failed to recreate the cursor.
309309
if resume_token is None:
310310
# There is no usable resume token because there was a
311-
# failure during ChangeStream initialization.
311+
# failure during AsyncChangeStream initialization.
312312
logging.error('...')
313313
else:
314-
# Use the interrupted ChangeStream's resume token to create
315-
# a new ChangeStream. The new stream will continue from the
314+
# Use the interrupted AsyncChangeStream's resume token to create
315+
# a new AsyncChangeStream. The new stream will continue from the
316316
# last seen insert change without missing any events.
317-
async with db.collection.watch(
317+
async with await db.collection.watch(
318318
pipeline, resume_after=resume_token) as stream:
319319
async for insert_change in stream:
320320
print(insert_change)
321321
322-
Raises :exc:`StopIteration` if this ChangeStream is closed.
322+
Raises :exc:`StopIteration` if this AsyncChangeStream is closed.
323323
"""
324324
while self.alive:
325325
doc = await self.try_next()
@@ -348,10 +348,10 @@ async def try_next(self) -> Optional[_DocumentType]:
348348
This method returns the next change document without waiting
349349
indefinitely for the next change. For example::
350350
351-
async with db.collection.watch() as stream:
351+
async with await db.collection.watch() as stream:
352352
while stream.alive:
353353
change = await stream.try_next()
354-
# Note that the ChangeStream's resume token may be updated
354+
# Note that the AsyncChangeStream's resume token may be updated
355355
# even when no changes are returned.
356356
print("Current resume token: %r" % (stream.resume_token,))
357357
if change is not None:
@@ -447,7 +447,7 @@ class AsyncCollectionChangeStream(AsyncChangeStream[_DocumentType]):
447447
"""A change stream that watches changes on a single collection.
448448
449449
Should not be called directly by application developers. Use
450-
helper method :meth:`pymongo.collection.AsyncCollection.watch` instead.
450+
helper method :meth:`pymongo.asynchronous.collection.AsyncCollection.watch` instead.
451451
452452
.. versionadded:: 3.7
453453
"""
@@ -467,7 +467,7 @@ class AsyncDatabaseChangeStream(AsyncChangeStream[_DocumentType]):
467467
"""A change stream that watches changes on all collections in a database.
468468
469469
Should not be called directly by application developers. Use
470-
helper method :meth:`pymongo.database.AsyncDatabase.watch` instead.
470+
helper method :meth:`pymongo.asynchronous.database.AsyncDatabase.watch` instead.
471471
472472
.. versionadded:: 3.7
473473
"""
@@ -487,7 +487,7 @@ class AsyncClusterChangeStream(AsyncDatabaseChangeStream[_DocumentType]):
487487
"""A change stream that watches changes on all collections in the cluster.
488488
489489
Should not be called directly by application developers. Use
490-
helper method :meth:`pymongo.mongo_client.AsyncMongoClient.watch` instead.
490+
helper method :meth:`pymongo.asynchronous.mongo_client.AsyncMongoClient.watch` instead.
491491
492492
.. versionadded:: 3.7
493493
"""

pymongo/asynchronous/client_session.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
103103
MongoDB 5.0 adds support for snapshot reads. Snapshot reads are requested by
104104
passing the ``snapshot`` option to
105-
:meth:`~pymongo.mongo_client.AsyncMongoClient.start_session`.
105+
:meth:`~pymongo.asynchronous.mongo_client.AsyncMongoClient.start_session`.
106106
If ``snapshot`` is True, all read operations that use this session read data
107107
from the same snapshot timestamp. The server chooses the latest
108108
majority-committed snapshot timestamp when executing the first read operation
@@ -123,11 +123,11 @@
123123
Snapshot reads sessions are incompatible with ``causal_consistency=True``.
124124
Only the following read operations are supported in a snapshot reads session:
125125
126-
- :meth:`~pymongo.collection.AsyncCollection.find`
127-
- :meth:`~pymongo.collection.AsyncCollection.find_one`
128-
- :meth:`~pymongo.collection.AsyncCollection.aggregate`
129-
- :meth:`~pymongo.collection.AsyncCollection.count_documents`
130-
- :meth:`~pymongo.collection.AsyncCollection.distinct` (on unsharded collections)
126+
- :meth:`~pymongo.asynchronous.collection.AsyncCollection.find`
127+
- :meth:`~pymongo.asynchronous.collection.AsyncCollection.find_one`
128+
- :meth:`~pymongo.asynchronous.collection.AsyncCollection.aggregate`
129+
- :meth:`~pymongo.asynchronous.collection.AsyncCollection.count_documents`
130+
- :meth:`~pymongo.asynchronous.collection.AsyncCollection.distinct` (on unsharded collections)
131131
132132
Classes
133133
=======
@@ -492,7 +492,7 @@ class AsyncClientSession:
492492
493493
Should not be initialized directly by application developers - to create a
494494
:class:`AsyncClientSession`, call
495-
:meth:`~pymongo.mongo_client.AsyncMongoClient.start_session`.
495+
:meth:`~pymongo.asynchronous.mongo_client.AsyncMongoClient.start_session`.
496496
"""
497497

498498
def __init__(
@@ -550,7 +550,7 @@ async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
550550

551551
@property
552552
def client(self) -> AsyncMongoClient:
553-
"""The :class:`~pymongo.mongo_client.AsyncMongoClient` this session was
553+
"""The :class:`~pymongo.asynchronous.mongo_client.AsyncMongoClient` this session was
554554
created from.
555555
"""
556556
return self._client
@@ -898,7 +898,7 @@ def advance_cluster_time(self, cluster_time: Mapping[str, Any]) -> None:
898898
"""Update the cluster time for this session.
899899
900900
:param cluster_time: The
901-
:data:`~pymongo.client_session.AsyncClientSession.cluster_time` from
901+
:data:`~pymongo.asynchronous.client_session.AsyncClientSession.cluster_time` from
902902
another `AsyncClientSession` instance.
903903
"""
904904
if not isinstance(cluster_time, _Mapping):
@@ -919,7 +919,7 @@ def advance_operation_time(self, operation_time: Timestamp) -> None:
919919
"""Update the operation time for this session.
920920
921921
:param operation_time: The
922-
:data:`~pymongo.client_session.AsyncClientSession.operation_time` from
922+
:data:`~pymongo.asynchronous.client_session.AsyncClientSession.operation_time` from
923923
another `AsyncClientSession` instance.
924924
"""
925925
if not isinstance(operation_time, Timestamp):
@@ -1133,7 +1133,7 @@ def pop_all(self) -> list[_ServerSession]:
11331133
def get_server_session(self, session_timeout_minutes: Optional[int]) -> _ServerSession:
11341134
# Although the Driver Sessions Spec says we only clear stale sessions
11351135
# in return_server_session, PyMongo can't take a lock when returning
1136-
# sessions from a __del__ method (like in Cursor.__die), so it can't
1136+
# sessions from a __del__ method (like in AsyncCursor.__die), so it can't
11371137
# clear stale sessions there. In case many sessions were returned via
11381138
# __del__, check for stale sessions here too.
11391139
self._clear_stale(session_timeout_minutes)

0 commit comments

Comments
 (0)