diff --git a/motor/core.pyi b/motor/core.pyi index dd308d31..a3bb96fd 100644 --- a/motor/core.pyi +++ b/motor/core.pyi @@ -16,7 +16,6 @@ from asyncio import Future from typing import ( Any, Callable, - Collection, Coroutine, Generic, Iterable, @@ -41,7 +40,7 @@ from pymongo import IndexModel, ReadPreference, WriteConcern from pymongo.change_stream import ChangeStream from pymongo.client_options import ClientOptions from pymongo.client_session import _T, ClientSession, SessionOptions, TransactionOptions -from pymongo.collection import ReturnDocument, _WriteOp # noqa: F401 +from pymongo.collection import Collection, ReturnDocument, _WriteOp # noqa: F401 from pymongo.command_cursor import CommandCursor, RawBatchCommandCursor from pymongo.cursor import Cursor, RawBatchCursor, _Hint, _Sort from pymongo.database import Database @@ -112,7 +111,7 @@ class AgnosticClient(AgnosticBaseProperties[_DocumentType]): read_preference: Optional[_ServerMode] = None, write_concern: Optional[WriteConcern] = None, read_concern: Optional[ReadConcern] = None, - ) -> Database[_DocumentType]: ... + ) -> AgnosticDatabase[_DocumentType]: ... def get_default_database( self, default: Optional[str] = None, @@ -120,7 +119,7 @@ class AgnosticClient(AgnosticBaseProperties[_DocumentType]): read_preference: Optional[_ServerMode] = None, write_concern: Optional[WriteConcern] = None, read_concern: Optional[ReadConcern] = None, - ) -> Database[_DocumentType]: ... + ) -> AgnosticDatabase[_DocumentType]: ... HOST: str @@ -578,7 +577,7 @@ class AgnosticCollection(AgnosticBaseProperties[_DocumentType]): read_preference: Optional[ReadPreference] = None, write_concern: Optional[WriteConcern] = None, read_concern: Optional[ReadConcern] = None, - ) -> Collection[Mapping[str, Any]]: ... + ) -> AgnosticCollection[Mapping[str, Any]]: ... def list_search_indexes( self, name: Optional[str] = None, diff --git a/motor/motor_asyncio.pyi b/motor/motor_asyncio.pyi index 5a9ca1c7..c3e2719f 100644 --- a/motor/motor_asyncio.pyi +++ b/motor/motor_asyncio.pyi @@ -1,9 +1,12 @@ -import sys +from typing import Any, Mapping, MutableMapping, Optional, Union -if sys.version_info >= (3, 8): - from typing import TypeAlias -else: - from typing_extensions import TypeAlias +from bson import Code, CodecOptions, Timestamp +from pymongo.client_session import TransactionOptions +from pymongo.cursor import _Hint, _Sort +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import ReadPreference, _ServerMode +from pymongo.typings import _CollationIn, _DocumentType, _DocumentTypeArg, _Pipeline +from pymongo.write_concern import WriteConcern from motor import core, motor_gridfs @@ -20,30 +23,236 @@ __all__: list[str] = [ "AsyncIOMotorGridOut", "AsyncIOMotorGridOutCursor", "AsyncIOMotorClientEncryption", + "AsyncIOMotorLatentCommandCursor", ] -AsyncIOMotorClient: TypeAlias = core.AgnosticClient +class AsyncIOMotorClient(core.AgnosticClient): + def get_database( + self, + name: Optional[str] = None, + codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, + read_preference: Optional[_ServerMode] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + ) -> AsyncIOMotorDatabase[_DocumentType]: ... + def get_default_database( + self, + default: Optional[str] = None, + codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, + read_preference: Optional[_ServerMode] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + ) -> AsyncIOMotorDatabase[_DocumentType]: ... + async def list_databases( + self, + session: Optional[core.AgnosticClientSession] = None, + comment: Optional[Any] = None, + **kwargs: Any, + ) -> AsyncIOMotorCommandCursor: ... + async def start_session( + self, + causal_consistency: Optional[bool] = None, + default_transaction_options: Optional[TransactionOptions] = None, + snapshot: Optional[bool] = False, + ) -> AsyncIOMotorClientSession: ... + def watch( + self, + pipeline: Optional[_Pipeline] = None, + full_document: Optional[str] = None, + resume_after: Optional[Mapping[str, Any]] = None, + max_await_time_ms: Optional[int] = None, + batch_size: Optional[int] = None, + collation: Optional[_CollationIn] = None, + start_at_operation_time: Optional[Timestamp] = None, + session: Optional[core.AgnosticClientSession] = None, + start_after: Optional[Mapping[str, Any]] = None, + comment: Optional[str] = None, + full_document_before_change: Optional[str] = None, + show_expanded_events: Optional[bool] = None, + ) -> AsyncIOMotorChangeStream: ... + def __getattr__(self, name: str) -> AsyncIOMotorDatabase: ... + def __getitem__(self, name: str) -> AsyncIOMotorDatabase: ... -AsyncIOMotorClientSession: TypeAlias = core.AgnosticClientSession +class AsyncIOMotorClientSession(core.AgnosticClientSession): + @property + def client(self) -> AsyncIOMotorClient: ... + async def __aenter__(self) -> AsyncIOMotorClientSession: ... -AsyncIOMotorDatabase: TypeAlias = core.AgnosticDatabase +class AsyncIOMotorDatabase(core.AgnosticDatabase): + async def cursor_command( + self, + command: Union[str, MutableMapping[str, Any]], + value: Any = 1, + read_preference: Optional[_ServerMode] = None, + codec_options: Optional[CodecOptions[core._CodecDocumentType]] = None, + session: Optional[core.AgnosticClientSession] = None, + comment: Optional[Any] = None, + max_await_time_ms: Optional[int] = None, + **kwargs: Any, + ) -> AsyncIOMotorCommandCursor: ... + async def create_collection( + self, + name: str, + codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, + read_preference: Optional[_ServerMode] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + session: Optional[core.AgnosticClientSession] = None, + check_exists: Optional[bool] = True, + **kwargs: Any, + ) -> AsyncIOMotorCollection: ... + def get_collection( + self, + name: str, + codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, + read_preference: Optional[_ServerMode] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + ) -> AsyncIOMotorCollection: ... + async def list_collections( + self, + session: Optional[core.AgnosticClientSession] = None, + filter: Optional[Mapping[str, Any]] = None, + comment: Optional[Any] = None, + **kwargs: Any, + ) -> AsyncIOMotorCommandCursor: ... + def with_options( + self, + codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, + read_preference: Optional[_ServerMode] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + ) -> AsyncIOMotorDatabase: ... + def aggregate( + self, pipeline: _Pipeline, *args: Any, **kwargs: Any + ) -> AsyncIOMotorLatentCommandCursor: ... + def watch( + self, + pipeline: Optional[_Pipeline] = None, + full_document: Optional[str] = None, + resume_after: Optional[Mapping[str, Any]] = None, + max_await_time_ms: Optional[int] = None, + batch_size: Optional[int] = None, + collation: Optional[_CollationIn] = None, + start_at_operation_time: Optional[Timestamp] = None, + session: Optional[core.AgnosticClientSession] = None, + start_after: Optional[Mapping[str, Any]] = None, + comment: Optional[Any] = None, + full_document_before_change: Optional[str] = None, + show_expanded_events: Optional[bool] = None, + ) -> AsyncIOMotorChangeStream: ... + @property + def client(self) -> AsyncIOMotorClient: ... + def __getattr__(self, name: str) -> AsyncIOMotorCollection: ... + def __getitem__(self, name: str) -> AsyncIOMotorCollection: ... -AsyncIOMotorCollection: TypeAlias = core.AgnosticCollection +class AsyncIOMotorCollection(core.AgnosticCollection): + def with_options( + self, + codec_options: Optional[CodecOptions] = None, + read_preference: Optional[ReadPreference] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + ) -> AsyncIOMotorCollection[Mapping[str, Any]]: ... + def list_search_indexes( + self, + name: Optional[str] = None, + session: Optional[core.AgnosticClientSession] = None, + comment: Optional[Any] = None, + **kwargs: Any, + ) -> AsyncIOMotorLatentCommandCursor: ... + def __getattr__(self, name: str) -> AsyncIOMotorCollection: ... + def __getitem__(self, name: str) -> AsyncIOMotorCollection: ... + def find(self, *args: Any, **kwargs: Any) -> AsyncIOMotorCursor: ... + def find_raw_batches(self, *args: Any, **kwargs: Any) -> AsyncIOMotorCursor: ... + def aggregate( + self, pipeline: _Pipeline, *args: Any, **kwargs: Any + ) -> AsyncIOMotorCommandCursor: ... + def aggregate_raw_batches( + self, pipeline: _Pipeline, **kwargs: Any + ) -> AsyncIOMotorCommandCursor: ... + def list_indexes( + self, session: Optional[core.AgnosticClientSession] = None, **kwargs: Any + ) -> AsyncIOMotorLatentCommandCursor: ... -AsyncIOMotorCursor: TypeAlias = core.AgnosticCursor +class AsyncIOMotorLatentCommandCursor(core.AgnosticLatentCommandCursor): ... -AsyncIOMotorCommandCursor: TypeAlias = core.AgnosticCommandCursor +class AsyncIOMotorCursor(core.AgnosticCursor): + def collation(self, collation: Optional[_CollationIn]) -> AsyncIOMotorCursor: ... + def add_option(self, mask: int) -> AsyncIOMotorCursor: ... + def remove_option(self, mask: int) -> AsyncIOMotorCursor: ... + def limit(self, limit: int) -> AsyncIOMotorCursor: ... + def skip(self, skip: int) -> AsyncIOMotorCursor: ... + def max_scan(self, max_scan: Optional[int]) -> AsyncIOMotorCursor: ... + def sort( + self, key_or_list: _Hint, direction: Optional[Union[int, str]] = None + ) -> AsyncIOMotorCursor: ... + def hint(self, index: Optional[_Hint]) -> AsyncIOMotorCursor: ... + def where(self, code: Union[str, Code]) -> AsyncIOMotorCursor: ... + def max_await_time_ms(self, max_await_time_ms: Optional[int]) -> AsyncIOMotorCursor: ... + def max_time_ms(self, max_time_ms: Optional[int]) -> AsyncIOMotorCursor: ... + def min(self, spec: _Sort) -> AsyncIOMotorCursor: ... + def max(self, spec: _Sort) -> AsyncIOMotorCursor: ... + def comment(self, comment: Any) -> AsyncIOMotorCursor: ... + def allow_disk_use(self, allow_disk_use: bool) -> AsyncIOMotorCursor: ... + def rewind(self) -> AsyncIOMotorCursor: ... + def clone(self) -> AsyncIOMotorCursor: ... + def __copy__(self) -> AsyncIOMotorCursor: ... + def __deepcopy__(self, memo: Any) -> AsyncIOMotorCursor: ... -AsyncIOMotorLatentCommandCursor: TypeAlias = core.AgnosticLatentCommandCursor +class AsyncIOMotorRawBatchCursor(core.AgnosticRawBatchCursor): ... +class AsyncIOMotorCommandCursor(core.AgnosticCommandCursor): ... +class AsyncIOMotorRawBatchCommandCursor(core.AgnosticRawBatchCommandCursor): ... -AsyncIOMotorChangeStream: TypeAlias = core.AgnosticChangeStream +class AsyncIOMotorChangeStream(core.AgnosticChangeStream): + def __aiter__(self) -> AsyncIOMotorChangeStream: ... + async def __aenter__(self) -> AsyncIOMotorChangeStream: ... -AsyncIOMotorGridFSBucket: TypeAlias = motor_gridfs.AgnosticGridFSBucket +class AsyncIOMotorClientEncryption(core.AgnosticClientEncryption): + async def __aenter__(self) -> AsyncIOMotorClientEncryption: ... + async def get_keys(self) -> AsyncIOMotorCursor: ... + async def create_encrypted_collection( + self, + database: core.AgnosticDatabase, + name: str, + encrypted_fields: Mapping[str, Any], + kms_provider: Optional[str] = None, + master_key: Optional[Mapping[str, Any]] = None, + **kwargs: Any, + ) -> tuple[AsyncIOMotorCollection, Mapping[str, Any]]: ... -AsyncIOMotorGridIn: TypeAlias = motor_gridfs.AgnosticGridIn +class AsyncIOMotorGridOutCursor(motor_gridfs.AgnosticGridOutCursor): + def next_object(self) -> AsyncIOMotorGridOutCursor: ... -AsyncIOMotorGridOut: TypeAlias = motor_gridfs.AgnosticGridOut +class AsyncIOMotorGridOut(motor_gridfs.AgnosticGridOut): + def __aiter__(self) -> AsyncIOMotorGridOut: ... -AsyncIOMotorGridOutCursor: TypeAlias = motor_gridfs.AgnosticGridOutCursor +class AsyncIOMotorGridIn(motor_gridfs.AgnosticGridIn): + async def __aenter__(self) -> AsyncIOMotorGridIn: ... -AsyncIOMotorClientEncryption: TypeAlias = core.AgnosticClientEncryption +class AsyncIOMotorGridFSBucket(motor_gridfs.AgnosticGridFSBucket): + async def open_download_stream_by_name( + self, + filename: str, + revision: int = -1, + session: Optional[core.AgnosticClientSession] = None, + ) -> AsyncIOMotorGridOut: ... + async def open_download_stream( + self, file_id: Any, session: Optional[core.AgnosticClientSession] = None + ) -> AsyncIOMotorGridOut: ... + def open_upload_stream( + self, + filename: str, + chunk_size_bytes: Optional[int] = None, + metadata: Optional[Mapping[str, Any]] = None, + session: Optional[core.AgnosticClientSession] = None, + ) -> AsyncIOMotorGridIn: ... + def open_upload_stream_with_id( + self, + file_id: Any, + filename: str, + chunk_size_bytes: Optional[int] = None, + metadata: Optional[Mapping[str, Any]] = None, + session: Optional[core.AgnosticClientSession] = None, + ) -> AsyncIOMotorGridIn: ... + def find(self, *args: Any, **kwargs: Any) -> AsyncIOMotorGridOutCursor: ... diff --git a/motor/motor_gridfs.pyi b/motor/motor_gridfs.pyi index 1cb1e85b..79ddde6c 100644 --- a/motor/motor_gridfs.pyi +++ b/motor/motor_gridfs.pyi @@ -127,17 +127,17 @@ class AgnosticGridFSBucket: ) -> None: ... async def open_download_stream_by_name( self, filename: str, revision: int = -1, session: Optional[AgnosticClientSession] = None - ) -> GridOut: ... + ) -> AgnosticGridOut: ... async def open_download_stream( self, file_id: Any, session: Optional[AgnosticClientSession] = None - ) -> GridOut: ... + ) -> AgnosticGridOut: ... def open_upload_stream( self, filename: str, chunk_size_bytes: Optional[int] = None, metadata: Optional[Mapping[str, Any]] = None, session: Optional[AgnosticClientSession] = None, - ) -> GridIn: ... + ) -> AgnosticGridIn: ... def open_upload_stream_with_id( self, file_id: Any, @@ -145,7 +145,7 @@ class AgnosticGridFSBucket: chunk_size_bytes: Optional[int] = None, metadata: Optional[Mapping[str, Any]] = None, session: Optional[AgnosticClientSession] = None, - ) -> GridIn: ... + ) -> AgnosticGridIn: ... async def rename( self, file_id: Any, new_filename: str, session: Optional[AgnosticClientSession] = None ) -> None: ... diff --git a/motor/motor_tornado.pyi b/motor/motor_tornado.pyi index ebe35d08..a4525be8 100644 --- a/motor/motor_tornado.pyi +++ b/motor/motor_tornado.pyi @@ -1,9 +1,12 @@ -import sys +from typing import Any, Mapping, MutableMapping, Optional, Union -if sys.version_info >= (3, 8): - from typing import TypeAlias -else: - from typing_extensions import TypeAlias +from bson import Code, CodecOptions, Timestamp +from pymongo.client_session import TransactionOptions +from pymongo.cursor import _Hint, _Sort +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import ReadPreference, _ServerMode +from pymongo.typings import _CollationIn, _DocumentType, _DocumentTypeArg, _Pipeline +from pymongo.write_concern import WriteConcern from motor import core, motor_gridfs @@ -22,28 +25,229 @@ __all__: list[str] = [ "MotorClientEncryption", ] -MotorClient: TypeAlias = core.AgnosticClient - -MotorClientSession: TypeAlias = core.AgnosticClientSession - -MotorDatabase: TypeAlias = core.AgnosticDatabase - -MotorCollection: TypeAlias = core.AgnosticCollection - -MotorCursor: TypeAlias = core.AgnosticCursor - -MotorCommandCursor: TypeAlias = core.AgnosticCommandCursor - -MotorLatentCommandCursor: TypeAlias = core.AgnosticLatentCommandCursor - -MotorChangeStream: TypeAlias = core.AgnosticChangeStream - -MotorGridFSBucket: TypeAlias = motor_gridfs.AgnosticGridFSBucket - -MotorGridIn: TypeAlias = motor_gridfs.AgnosticGridIn - -MotorGridOut: TypeAlias = motor_gridfs.AgnosticGridOut - -MotorGridOutCursor: TypeAlias = motor_gridfs.AgnosticGridOutCursor - -MotorClientEncryption: TypeAlias = core.AgnosticClientEncryption +class MotorClient(core.AgnosticClient): + def get_database( + self, + name: Optional[str] = None, + codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, + read_preference: Optional[_ServerMode] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + ) -> MotorDatabase[_DocumentType]: ... + def get_default_database( + self, + default: Optional[str] = None, + codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, + read_preference: Optional[_ServerMode] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + ) -> MotorDatabase[_DocumentType]: ... + async def list_databases( + self, + session: Optional[core.AgnosticClientSession] = None, + comment: Optional[Any] = None, + **kwargs: Any, + ) -> MotorCommandCursor: ... + async def start_session( + self, + causal_consistency: Optional[bool] = None, + default_transaction_options: Optional[TransactionOptions] = None, + snapshot: Optional[bool] = False, + ) -> MotorClientSession: ... + def watch( + self, + pipeline: Optional[_Pipeline] = None, + full_document: Optional[str] = None, + resume_after: Optional[Mapping[str, Any]] = None, + max_await_time_ms: Optional[int] = None, + batch_size: Optional[int] = None, + collation: Optional[_CollationIn] = None, + start_at_operation_time: Optional[Timestamp] = None, + session: Optional[core.AgnosticClientSession] = None, + start_after: Optional[Mapping[str, Any]] = None, + comment: Optional[str] = None, + full_document_before_change: Optional[str] = None, + show_expanded_events: Optional[bool] = None, + ) -> MotorChangeStream: ... + def __getattr__(self, name: str) -> MotorDatabase: ... + def __getitem__(self, name: str) -> MotorDatabase: ... + +class MotorClientSession(core.AgnosticClientSession): + @property + def client(self) -> MotorClient: ... + async def __aenter__(self) -> MotorClientSession: ... + +class MotorDatabase(core.AgnosticDatabase): + async def cursor_command( + self, + command: Union[str, MutableMapping[str, Any]], + value: Any = 1, + read_preference: Optional[_ServerMode] = None, + codec_options: Optional[CodecOptions[core._CodecDocumentType]] = None, + session: Optional[core.AgnosticClientSession] = None, + comment: Optional[Any] = None, + max_await_time_ms: Optional[int] = None, + **kwargs: Any, + ) -> MotorCommandCursor: ... + async def create_collection( + self, + name: str, + codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, + read_preference: Optional[_ServerMode] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + session: Optional[core.AgnosticClientSession] = None, + check_exists: Optional[bool] = True, + **kwargs: Any, + ) -> MotorCollection: ... + def get_collection( + self, + name: str, + codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, + read_preference: Optional[_ServerMode] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + ) -> MotorCollection: ... + async def list_collections( + self, + session: Optional[core.AgnosticClientSession] = None, + filter: Optional[Mapping[str, Any]] = None, + comment: Optional[Any] = None, + **kwargs: Any, + ) -> MotorCommandCursor: ... + def with_options( + self, + codec_options: Optional[CodecOptions[_DocumentTypeArg]] = None, + read_preference: Optional[_ServerMode] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + ) -> MotorDatabase: ... + def aggregate( + self, pipeline: _Pipeline, *args: Any, **kwargs: Any + ) -> MotorLatentCommandCursor: ... + def watch( + self, + pipeline: Optional[_Pipeline] = None, + full_document: Optional[str] = None, + resume_after: Optional[Mapping[str, Any]] = None, + max_await_time_ms: Optional[int] = None, + batch_size: Optional[int] = None, + collation: Optional[_CollationIn] = None, + start_at_operation_time: Optional[Timestamp] = None, + session: Optional[core.AgnosticClientSession] = None, + start_after: Optional[Mapping[str, Any]] = None, + comment: Optional[Any] = None, + full_document_before_change: Optional[str] = None, + show_expanded_events: Optional[bool] = None, + ) -> MotorChangeStream: ... + @property + def client(self) -> MotorClient: ... + def __getattr__(self, name: str) -> MotorCollection: ... + def __getitem__(self, name: str) -> MotorCollection: ... + +class MotorCollection(core.AgnosticCollection): + def with_options( + self, + codec_options: Optional[CodecOptions] = None, + read_preference: Optional[ReadPreference] = None, + write_concern: Optional[WriteConcern] = None, + read_concern: Optional[ReadConcern] = None, + ) -> MotorCollection[Mapping[str, Any]]: ... + def list_search_indexes( + self, + name: Optional[str] = None, + session: Optional[core.AgnosticClientSession] = None, + comment: Optional[Any] = None, + **kwargs: Any, + ) -> MotorLatentCommandCursor: ... + def __getattr__(self, name: str) -> MotorCollection: ... + def __getitem__(self, name: str) -> MotorCollection: ... + def find(self, *args: Any, **kwargs: Any) -> MotorCursor: ... + def find_raw_batches(self, *args: Any, **kwargs: Any) -> MotorCursor: ... + def aggregate(self, pipeline: _Pipeline, *args: Any, **kwargs: Any) -> MotorCommandCursor: ... + def aggregate_raw_batches(self, pipeline: _Pipeline, **kwargs: Any) -> MotorCommandCursor: ... + def list_indexes( + self, session: Optional[core.AgnosticClientSession] = None, **kwargs: Any + ) -> MotorLatentCommandCursor: ... + +class MotorLatentCommandCursor(core.AgnosticLatentCommandCursor): ... + +class MotorCursor(core.AgnosticCursor): + def collation(self, collation: Optional[_CollationIn]) -> MotorCursor: ... + def add_option(self, mask: int) -> MotorCursor: ... + def remove_option(self, mask: int) -> MotorCursor: ... + def limit(self, limit: int) -> MotorCursor: ... + def skip(self, skip: int) -> MotorCursor: ... + def max_scan(self, max_scan: Optional[int]) -> MotorCursor: ... + def sort( + self, key_or_list: _Hint, direction: Optional[Union[int, str]] = None + ) -> MotorCursor: ... + def hint(self, index: Optional[_Hint]) -> MotorCursor: ... + def where(self, code: Union[str, Code]) -> MotorCursor: ... + def max_await_time_ms(self, max_await_time_ms: Optional[int]) -> MotorCursor: ... + def max_time_ms(self, max_time_ms: Optional[int]) -> MotorCursor: ... + def min(self, spec: _Sort) -> MotorCursor: ... + def max(self, spec: _Sort) -> MotorCursor: ... + def comment(self, comment: Any) -> MotorCursor: ... + def allow_disk_use(self, allow_disk_use: bool) -> MotorCursor: ... + def rewind(self) -> MotorCursor: ... + def clone(self) -> MotorCursor: ... + def __copy__(self) -> MotorCursor: ... + def __deepcopy__(self, memo: Any) -> MotorCursor: ... + +class MotorRawBatchCursor(core.AgnosticRawBatchCursor): ... +class MotorCommandCursor(core.AgnosticCommandCursor): ... +class MotorRawBatchCommandCursor(core.AgnosticRawBatchCommandCursor): ... + +class MotorChangeStream(core.AgnosticChangeStream): + def __aiter__(self) -> MotorChangeStream: ... + async def __aenter__(self) -> MotorChangeStream: ... + +class MotorClientEncryption(core.AgnosticClientEncryption): + async def __aenter__(self) -> MotorClientEncryption: ... + async def get_keys(self) -> MotorCursor: ... + async def create_encrypted_collection( + self, + database: core.AgnosticDatabase, + name: str, + encrypted_fields: Mapping[str, Any], + kms_provider: Optional[str] = None, + master_key: Optional[Mapping[str, Any]] = None, + **kwargs: Any, + ) -> tuple[MotorCollection, Mapping[str, Any]]: ... + +class MotorGridOutCursor(motor_gridfs.AgnosticGridOutCursor): + def next_object(self) -> MotorGridOutCursor: ... + +class MotorGridOut(motor_gridfs.AgnosticGridOut): + def __aiter__(self) -> MotorGridOut: ... + +class MotorGridIn(motor_gridfs.AgnosticGridIn): + async def __aenter__(self) -> MotorGridIn: ... + +class MotorGridFSBucket(motor_gridfs.AgnosticGridFSBucket): + async def open_download_stream_by_name( + self, + filename: str, + revision: int = -1, + session: Optional[core.AgnosticClientSession] = None, + ) -> MotorGridOut: ... + async def open_download_stream( + self, file_id: Any, session: Optional[core.AgnosticClientSession] = None + ) -> MotorGridOut: ... + def open_upload_stream( + self, + filename: str, + chunk_size_bytes: Optional[int] = None, + metadata: Optional[Mapping[str, Any]] = None, + session: Optional[core.AgnosticClientSession] = None, + ) -> MotorGridIn: ... + def open_upload_stream_with_id( + self, + file_id: Any, + filename: str, + chunk_size_bytes: Optional[int] = None, + metadata: Optional[Mapping[str, Any]] = None, + session: Optional[core.AgnosticClientSession] = None, + ) -> MotorGridIn: ... + def find(self, *args: Any, **kwargs: Any) -> MotorGridOutCursor: ... diff --git a/test/asyncio_tests/__init__.py b/test/asyncio_tests/__init__.py index a1ee767f..6346ed74 100644 --- a/test/asyncio_tests/__init__.py +++ b/test/asyncio_tests/__init__.py @@ -28,7 +28,6 @@ from mockupdb import MockupDB from motor import motor_asyncio -from motor.core import AgnosticClient # mypy: ignore-errors @@ -107,7 +106,9 @@ def get_client_kwargs(self, set_loop=True, **kwargs): kwargs.setdefault("tls", env.mongod_started_with_ssl) return kwargs - def asyncio_client(self, uri=None, *args, set_loop=True, **kwargs) -> AgnosticClient: + def asyncio_client( + self, uri=None, *args, set_loop=True, **kwargs + ) -> motor_asyncio.AsyncIOMotorClient: """Get an AsyncIOMotorClient. Ignores self.ssl, you must pass 'ssl' argument. diff --git a/test/test_typing.py b/test/test_typing.py index bb8ebc33..7a3dd2eb 100644 --- a/test/test_typing.py +++ b/test/test_typing.py @@ -25,7 +25,7 @@ from pymongo.operations import DeleteOne, InsertOne, ReplaceOne from pymongo.read_preferences import ReadPreference -from motor.core import AgnosticClient, AgnosticCollection +from motor.motor_asyncio import AsyncIOMotorClient try: from bson import ObjectId @@ -66,12 +66,12 @@ def inner(*args: Any, **kwargs: Any) -> Any: class TestMotor(AsyncIOTestCase): - cx: AgnosticClient + cx: AsyncIOMotorClient @asyncio_test # type:ignore[misc] async def test_insert_find(self) -> None: doc = {"my": "doc"} - coll: AgnosticCollection = self.collection + coll = self.collection coll2 = self.cx.test.test2 result = await coll.insert_one(doc) self.assertEqual(result.inserted_id, doc["_id"]) @@ -94,9 +94,15 @@ async def test_get_collection(self) -> None: coll = self.db.get_collection("test_collection") self.assertEqual(coll.name, "test_collection") + @asyncio_test # type:ignore[misc] + async def test_get_database(self) -> None: + db1 = self.cx.get_database("test_database") + db2 = self.cx["test_database"] + self.assertEqual(db1.client, db2.client) + @asyncio_test # type:ignore[misc] async def test_find_one(self) -> None: - c: AgnosticClient[Movie] = self.asyncio_client() + c: AsyncIOMotorClient[Movie] = self.asyncio_client() coll = c[self.db.name]["movies"] await coll.insert_one(Movie(name="American Graffiti", year=1973)) result = await coll.find_one({}) @@ -107,7 +113,7 @@ async def test_find_one(self) -> None: @asyncio_test # type:ignore[misc] async def test_bulk_write(self) -> None: await self.collection.insert_one({}) - coll: AgnosticCollection = self.collection + coll = self.collection requests: List[InsertOne[Movie]] = [InsertOne(Movie(name="American Graffiti", year=1973))] result_one = await coll.bulk_write(requests) self.assertTrue(result_one.acknowledged) @@ -125,7 +131,7 @@ async def test_bulk_write(self) -> None: @only_type_check @asyncio_test # type:ignore[misc] async def test_bulk_write_heterogeneous(self) -> None: - coll: AgnosticCollection = self.collection + coll = self.collection requests: List[Union[InsertOne[Movie], ReplaceOne, DeleteOne]] = [ InsertOne(Movie(name="American Graffiti", year=1973)), ReplaceOne({}, {"name": "American Graffiti", "year": "WRONG_TYPE"}), @@ -240,20 +246,20 @@ def test_typeddict_empty_document_type(self) -> None: class TestCommandDocumentType(AsyncIOTestCase): @only_type_check async def test_default(self) -> None: - client: AgnosticClient = AgnosticClient() + client: AsyncIOMotorClient = AsyncIOMotorClient() result: Dict = await client.admin.command("ping") result["a"] = 1 @only_type_check async def test_explicit_document_type(self) -> None: - client: AgnosticClient = AgnosticClient() + client: AsyncIOMotorClient = AsyncIOMotorClient() codec_options: CodecOptions[Dict[str, Any]] = CodecOptions() result = await client.admin.command("ping", codec_options=codec_options) result["a"] = 1 @only_type_check async def test_typeddict_document_type(self) -> None: - client: AgnosticClient = AgnosticClient() + client: AsyncIOMotorClient = AsyncIOMotorClient() codec_options: CodecOptions[Movie] = CodecOptions() result = await client.admin.command("ping", codec_options=codec_options) assert result["year"] == 1 @@ -261,7 +267,7 @@ async def test_typeddict_document_type(self) -> None: @only_type_check async def test_raw_bson_document_type(self) -> None: - client: AgnosticClient = AgnosticClient() + client: AsyncIOMotorClient = AsyncIOMotorClient() codec_options = CodecOptions(RawBSONDocument) result = await client.admin.command( "ping", codec_options=codec_options @@ -270,7 +276,7 @@ async def test_raw_bson_document_type(self) -> None: @only_type_check async def test_son_document_type(self) -> None: - client: AgnosticClient[SON[str, Any]] = AgnosticClient(document_class=SON[str, Any]) + client: AsyncIOMotorClient[SON[str, Any]] = AsyncIOMotorClient(document_class=SON[str, Any]) codec_options = CodecOptions(SON[str, Any]) result = await client.admin.command("ping", codec_options=codec_options) result["a"] = 1 diff --git a/tox.ini b/tox.ini index d90937dd..61a6e5b0 100644 --- a/tox.ini +++ b/tox.ini @@ -159,7 +159,6 @@ extras = test deps = mypy==1.7.0 - typing_extensions setuptools==68.0.0 setenv = SKIP_ENV_SETUP=1