Skip to content

Commit ffa6555

Browse files
authored
PYTHON-4476 Separate data and IO classes more effectively (#1678)
1 parent 1c2f1f5 commit ffa6555

File tree

175 files changed

+9157
-20015
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+9157
-20015
lines changed

gridfs/asynchronous/grid_file.py

Lines changed: 55 additions & 49 deletions
Large diffs are not rendered by default.

gridfs/grid_file_shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Any, Optional
66

77
from pymongo import ASCENDING
8-
from pymongo.asynchronous.common import MAX_MESSAGE_SIZE
8+
from pymongo.common import MAX_MESSAGE_SIZE
99
from pymongo.errors import InvalidOperation
1010

1111
_SEEK_SET = os.SEEK_SET

gridfs/synchronous/grid_file.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
_grid_out_property,
4343
)
4444
from pymongo import ASCENDING, DESCENDING, WriteConcern, _csot
45+
from pymongo.common import validate_string
4546
from pymongo.errors import (
4647
BulkWriteError,
4748
ConfigurationError,
@@ -50,13 +51,13 @@
5051
InvalidOperation,
5152
OperationFailure,
5253
)
54+
from pymongo.helpers_shared import _check_write_command_response
55+
from pymongo.read_preferences import ReadPreference, _ServerMode
5356
from pymongo.synchronous.client_session import ClientSession
5457
from pymongo.synchronous.collection import Collection
55-
from pymongo.synchronous.common import validate_string
5658
from pymongo.synchronous.cursor import Cursor
5759
from pymongo.synchronous.database import Database
58-
from pymongo.synchronous.helpers import _check_write_command_response, next
59-
from pymongo.synchronous.read_preferences import ReadPreference, _ServerMode
60+
from pymongo.synchronous.helpers import next
6061

6162
_IS_SYNC = True
6263

@@ -234,7 +235,10 @@ def get_version(
234235
raise NoFile("no version %d for filename %r" % (version, filename)) from None
235236

236237
def get_last_version(
237-
self, filename: Optional[str] = None, session: Optional[ClientSession] = None, **kwargs: Any
238+
self,
239+
filename: Optional[str] = None,
240+
session: Optional[ClientSession] = None,
241+
**kwargs: Any,
238242
) -> GridOut:
239243
"""Get the most recent version of a file in GridFS by ``"filename"``
240244
or metadata fields.
@@ -497,7 +501,7 @@ def __init__(
497501
.. seealso:: The MongoDB documentation on `gridfs <https://dochub.mongodb.org/core/gridfs>`_.
498502
"""
499503
if not isinstance(db, Database):
500-
raise TypeError("database must be an instance of AsyncDatabase")
504+
raise TypeError("database must be an instance of Database")
501505

502506
db = _clear_entity_type_registry(db)
503507

@@ -1028,7 +1032,7 @@ def __init__(
10281032
provided by :class:`~gridfs.GridFS`.
10291033
10301034
Raises :class:`TypeError` if `root_collection` is not an
1031-
instance of :class:`~pymongo.collection.AsyncCollection`.
1035+
instance of :class:`~pymongo.collection.Collection`.
10321036
10331037
Any of the file level options specified in the `GridFS Spec
10341038
<http://dochub.mongodb.org/core/gridfsspec>`_ may be passed as
@@ -1069,10 +1073,10 @@ def __init__(
10691073
10701074
.. versionchanged:: 3.0
10711075
`root_collection` must use an acknowledged
1072-
:attr:`~pymongo.collection.AsyncCollection.write_concern`
1076+
:attr:`~pymongo.collection.Collection.write_concern`
10731077
"""
10741078
if not isinstance(root_collection, Collection):
1075-
raise TypeError("root_collection must be an instance of AsyncCollection")
1079+
raise TypeError("root_collection must be an instance of Collection")
10761080

10771081
if not root_collection.write_concern.acknowledged:
10781082
raise ConfigurationError("root_collection must use acknowledged write_concern")
@@ -1401,7 +1405,7 @@ def __init__(
14011405
Either `file_id` or `file_document` must be specified,
14021406
`file_document` will be given priority if present. Raises
14031407
:class:`TypeError` if `root_collection` is not an instance of
1404-
:class:`~pymongo.collection.AsyncCollection`.
1408+
:class:`~pymongo.collection.Collection`.
14051409
14061410
:param root_collection: root collection to read from
14071411
:param file_id: value of ``"_id"`` for the file to read
@@ -1424,7 +1428,7 @@ def __init__(
14241428
from the server. Metadata is fetched when first needed.
14251429
"""
14261430
if not isinstance(root_collection, Collection):
1427-
raise TypeError("root_collection must be an instance of AsyncCollection")
1431+
raise TypeError("root_collection must be an instance of Collection")
14281432
_disallow_transactions(session)
14291433

14301434
root_collection = _clear_entity_type_registry(root_collection)
@@ -1482,7 +1486,7 @@ def __getattr__(self, name: str) -> Any:
14821486
self.open() # type: ignore[unused-coroutine]
14831487
elif not self._file:
14841488
raise InvalidOperation(
1485-
"You must call AsyncGridOut.open() before accessing the %s property" % name
1489+
"You must call GridOut.open() before accessing the %s property" % name
14861490
)
14871491
if name in self._file:
14881492
return self._file[name]
@@ -1677,13 +1681,13 @@ def writable(self) -> bool:
16771681
return False
16781682

16791683
def __enter__(self) -> GridOut:
1680-
"""Makes it possible to use :class:`AsyncGridOut` files
1684+
"""Makes it possible to use :class:`GridOut` files
16811685
with the async context manager protocol.
16821686
"""
16831687
return self
16841688

16851689
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> Any:
1686-
"""Makes it possible to use :class:`AsyncGridOut` files
1690+
"""Makes it possible to use :class:`GridOut` files
16871691
with the async context manager protocol.
16881692
"""
16891693
self.close()

pymongo/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,9 @@
8989
from pymongo import _csot
9090
from pymongo._version import __version__, get_version_string, version_tuple
9191
from pymongo.asynchronous.mongo_client import AsyncMongoClient
92+
from pymongo.common import MAX_SUPPORTED_WIRE_VERSION, MIN_SUPPORTED_WIRE_VERSION
9293
from pymongo.cursor import CursorType
93-
from pymongo.synchronous.collection import ReturnDocument
94-
from pymongo.synchronous.common import MAX_SUPPORTED_WIRE_VERSION, MIN_SUPPORTED_WIRE_VERSION
95-
from pymongo.synchronous.mongo_client import MongoClient
96-
from pymongo.synchronous.operations import (
94+
from pymongo.operations import (
9795
DeleteMany,
9896
DeleteOne,
9997
IndexModel,
@@ -102,7 +100,9 @@
102100
UpdateMany,
103101
UpdateOne,
104102
)
105-
from pymongo.synchronous.read_preferences import ReadPreference
103+
from pymongo.read_preferences import ReadPreference
104+
from pymongo.synchronous.collection import ReturnDocument
105+
from pymongo.synchronous.mongo_client import MongoClient
106106
from pymongo.write_concern import WriteConcern
107107

108108
version = __version__

pymongo/asynchronous/aggregation.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
from collections.abc import Callable, Mapping, MutableMapping
1919
from typing import TYPE_CHECKING, Any, Optional, Union
2020

21-
from pymongo.asynchronous import common
22-
from pymongo.asynchronous.collation import validate_collation_or_none
23-
from pymongo.asynchronous.read_preferences import ReadPreference, _AggWritePref
21+
from pymongo import common
22+
from pymongo.collation import validate_collation_or_none
2423
from pymongo.errors import ConfigurationError
24+
from pymongo.read_preferences import ReadPreference, _AggWritePref
2525

2626
if TYPE_CHECKING:
27-
from pymongo.asynchronous.client_session import ClientSession
27+
from pymongo.asynchronous.client_session import AsyncClientSession
2828
from pymongo.asynchronous.collection import AsyncCollection
2929
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
3030
from pymongo.asynchronous.database import AsyncDatabase
31-
from pymongo.asynchronous.pool import Connection
32-
from pymongo.asynchronous.read_preferences import _ServerMode
31+
from pymongo.asynchronous.pool import AsyncConnection
3332
from pymongo.asynchronous.server import Server
34-
from pymongo.asynchronous.typings import _DocumentType, _Pipeline
33+
from pymongo.read_preferences import _ServerMode
34+
from pymongo.typings import _DocumentType, _Pipeline
3535

3636
_IS_SYNC = False
3737

@@ -53,7 +53,7 @@ def __init__(
5353
explicit_session: bool,
5454
let: Optional[Mapping[str, Any]] = None,
5555
user_fields: Optional[MutableMapping[str, Any]] = None,
56-
result_processor: Optional[Callable[[Mapping[str, Any], Connection], None]] = None,
56+
result_processor: Optional[Callable[[Mapping[str, Any], AsyncConnection], None]] = None,
5757
comment: Any = None,
5858
) -> None:
5959
if "explain" in options:
@@ -121,7 +121,7 @@ def _database(self) -> AsyncDatabase:
121121
raise NotImplementedError
122122

123123
def get_read_preference(
124-
self, session: Optional[ClientSession]
124+
self, session: Optional[AsyncClientSession]
125125
) -> Union[_AggWritePref, _ServerMode]:
126126
if self._write_preference:
127127
return self._write_preference
@@ -132,9 +132,9 @@ def get_read_preference(
132132

133133
async def get_cursor(
134134
self,
135-
session: Optional[ClientSession],
135+
session: Optional[AsyncClientSession],
136136
server: Server,
137-
conn: Connection,
137+
conn: AsyncConnection,
138138
read_preference: _ServerMode,
139139
) -> AsyncCommandCursor[_DocumentType]:
140140
# Serialize command.

0 commit comments

Comments
 (0)