From 978a12ad36b1b4b8d05e7cb43b1509db01848f23 Mon Sep 17 00:00:00 2001 From: Grier Phillips Date: Tue, 26 Dec 2017 13:18:01 -0700 Subject: [PATCH 1/2] Add stub files for pymongo --- pymongo/__init__.pyi | 35 ++++++ pymongo/auth.pyi | 29 +++++ pymongo/bulk.pyi | 61 +++++++++++ pymongo/client_options.pyi | 44 ++++++++ pymongo/collation.pyi | 27 +++++ pymongo/collection.pyi | 91 ++++++++++++++++ pymongo/command_cursor.pyi | 24 +++++ pymongo/common.pyi | 84 +++++++++++++++ pymongo/cursor.pyi | 68 ++++++++++++ pymongo/cursor_manager.pyi | 8 ++ pymongo/database.pyi | 80 ++++++++++++++ pymongo/errors.pyi | 33 ++++++ pymongo/helpers.pyi | 21 ++++ pymongo/ismaster.pyi | 40 +++++++ pymongo/max_staleness_selectors.pyi | 9 ++ pymongo/message.pyi | 81 ++++++++++++++ pymongo/mongo_client.pyi | 100 +++++++++++++++++ pymongo/mongo_replica_set_client.pyi | 8 ++ pymongo/monitor.pyi | 19 ++++ pymongo/monitoring.pyi | 154 +++++++++++++++++++++++++++ pymongo/network.pyi | 18 ++++ pymongo/operations.pyi | 44 ++++++++ pymongo/periodic_executor.pyi | 16 +++ pymongo/pool.pyi | 76 +++++++++++++ pymongo/read_concern.pyi | 14 +++ pymongo/read_preferences.pyi | 75 +++++++++++++ pymongo/response.pyi | 25 +++++ pymongo/results.pyi | 54 ++++++++++ pymongo/server.pyi | 33 ++++++ pymongo/server_description.pyi | 56 ++++++++++ pymongo/server_selectors.pyi | 31 ++++++ pymongo/server_type.pyi | 13 +++ pymongo/settings.pyi | 32 ++++++ pymongo/son_manipulator.pyi | 26 +++++ pymongo/ssl_context.pyi | 18 ++++ pymongo/ssl_match_hostname.pyi | 6 ++ pymongo/ssl_support.pyi | 5 + pymongo/thread_util.pyi | 29 +++++ pymongo/topology.pyi | 42 ++++++++ pymongo/topology_description.pyi | 50 +++++++++ pymongo/write_concern.pyi | 12 +++ 41 files changed, 1691 insertions(+) create mode 100644 pymongo/__init__.pyi create mode 100644 pymongo/auth.pyi create mode 100644 pymongo/bulk.pyi create mode 100644 pymongo/client_options.pyi create mode 100644 pymongo/collation.pyi create mode 100644 pymongo/collection.pyi create mode 100644 pymongo/command_cursor.pyi create mode 100644 pymongo/common.pyi create mode 100644 pymongo/cursor.pyi create mode 100644 pymongo/cursor_manager.pyi create mode 100644 pymongo/database.pyi create mode 100644 pymongo/errors.pyi create mode 100644 pymongo/helpers.pyi create mode 100644 pymongo/ismaster.pyi create mode 100644 pymongo/max_staleness_selectors.pyi create mode 100644 pymongo/message.pyi create mode 100644 pymongo/mongo_client.pyi create mode 100644 pymongo/mongo_replica_set_client.pyi create mode 100644 pymongo/monitor.pyi create mode 100644 pymongo/monitoring.pyi create mode 100644 pymongo/network.pyi create mode 100644 pymongo/operations.pyi create mode 100644 pymongo/periodic_executor.pyi create mode 100644 pymongo/pool.pyi create mode 100644 pymongo/read_concern.pyi create mode 100644 pymongo/read_preferences.pyi create mode 100644 pymongo/response.pyi create mode 100644 pymongo/results.pyi create mode 100644 pymongo/server.pyi create mode 100644 pymongo/server_description.pyi create mode 100644 pymongo/server_selectors.pyi create mode 100644 pymongo/server_type.pyi create mode 100644 pymongo/settings.pyi create mode 100644 pymongo/son_manipulator.pyi create mode 100644 pymongo/ssl_context.pyi create mode 100644 pymongo/ssl_match_hostname.pyi create mode 100644 pymongo/ssl_support.pyi create mode 100644 pymongo/thread_util.pyi create mode 100644 pymongo/topology.pyi create mode 100644 pymongo/topology_description.pyi create mode 100644 pymongo/write_concern.pyi diff --git a/pymongo/__init__.pyi b/pymongo/__init__.pyi new file mode 100644 index 0000000000..a48c9a654a --- /dev/null +++ b/pymongo/__init__.pyi @@ -0,0 +1,35 @@ +ASCENDING: int = ... +DESCENDING: int = ... +GEO2D: str = ... +GEOHAYSTACK: str = ... +GEOSPHERE: str = ... +HASHED: str = ... +TEXT: str = ... +OFF: int = ... +SLOW_ONLY: int = ... +ALL: int = ... +version_tuple = (3, 5, 0, '.dev0') + + +def get_version_string() -> str: ... + + +__version__ = version = ... + +from pymongo.collection import ReturnDocument +from pymongo.common import (MIN_SUPPORTED_WIRE_VERSION, + MAX_SUPPORTED_WIRE_VERSION) +from pymongo.cursor import CursorType +from pymongo.mongo_client import MongoClient +from pymongo.mongo_replica_set_client import MongoReplicaSetClient +from pymongo.operations import (IndexModel, + InsertOne, + DeleteOne, + DeleteMany, + UpdateOne, + UpdateMany, + ReplaceOne) +from pymongo.read_preferences import ReadPreference +from pymongo.write_concern import WriteConcern + +def has_c() -> bool: ... diff --git a/pymongo/auth.pyi b/pymongo/auth.pyi new file mode 100644 index 0000000000..0729977569 --- /dev/null +++ b/pymongo/auth.pyi @@ -0,0 +1,29 @@ +from typing import Any, Dict, FrozenSet, NamedTuple + +from pymongo.pool import SocketInfo + +MECHANISMS: FrozenSet[str] = ... + +class MongoCredential(NamedTuple): + mechanism: str + source: str + username: str + password: str + props: Any +class GSSAPIProperties(NamedTuple): + service_name: str + canonicalize_host_name: bool + service_realm: Any +def _build_credentials_tuple(mech: str, source: str, user: str, passwd: str, extra: Dict[str, Any]) -> MongoCredential: ... +def _parse_scram_response(response: bytes) -> Dict[bytes, int]: ... +def _authenticate_scram_sha1(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... +def _password_digest(username: str, password: str) -> str: ... +def _auth_key(nonce: str, username: str, password: str) -> str: ... +def _authenticate_gssapi(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... +def _authenticate_plain(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... +def _authenticate_cram_md5(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... +def _authenticate_x509(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... +def _authenticate_mongo_cr(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... +def _authenticate_default(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... +def authenticate(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... +def logout(source: str, sock_info: SocketInfo) -> None: ... diff --git a/pymongo/bulk.pyi b/pymongo/bulk.pyi new file mode 100644 index 0000000000..e5b8bd8d8e --- /dev/null +++ b/pymongo/bulk.pyi @@ -0,0 +1,61 @@ +from typing import Any, Dict, Iterator, List, Optional, Tuple, Union + +from pymongo.collation import Collation +from pymongo.collection import Collection +from pymongo.pool import SocketInfo +from pymongo.write_concern import WriteConcern + + +_DELETE_ALL: int = ... +_DELETE_ONE: int = ... +_BAD_VALUE: int = ... +_UNKNOWN_ERROR: int = ... +_WRITE_CONCERN_ERROR: int = ... +_COMMANDS: Tuple[str, str, str] = ... +_UID: str = ... +_UCODE: str = ... +_UERRMSG: str = ... +_UINDEX: str = ... +_UOP: str = ... + +class _Run(object): + def __init__(self, op_type: int) -> None: ... + def index(self, idx: int) -> int: ... + def add(self, original_index: int, operation: Dict[str, Any]) -> None: ... +def _make_error(index: int, code: int, errmsg: str, operation: Dict[str, Any]) -> Dict[str, Any]: ... +def _merge_legacy(run: _Run, full_result: Dict[str, Any], result: Dict[str, Any], index: int) -> None: ... +def _merge_command(run: _Run, full_result: Dict[str, Any], results: List[Tuple[int, Dict[str, Any]]]) -> None: ... + +class _Bulk(object): + def __init__(self, collection: Collection, ordered: bool, bypass_document_validation: bool) -> None: ... + def add_insert(self, document: Dict[str, Any]) -> None: ... + def add_update(self, selector: Dict[str, Any], update: Dict[str, Any], multi: bool = ..., upsert: bool = ..., collation: Optional[Collation] = ...) -> None: ... + def add_replace(self, selector: Dict[str, Any], replacement: Dict[str, Any], upsert: bool = ..., collation: Optional[Collation] = ...) -> None: ... + def add_delete(self, selector: Dict[str, Any], limit: int, collation: Optional[Collation] = ...) -> None: ... + def gen_ordered(self) -> _Run: ... + def gen_unordered(self) -> _Run: ... + def execute_command(self, sock_info: SocketInfo, generator: Iterator[_Run], write_concern: WriteConcern) -> Dict[str, Any]: ... + def execute_no_results(self, sock_info: SocketInfo, generator: Iterator[_Run]) -> None: ... + def execute_legacy(self, sock_info: SocketInfo, generator: Iterator[_Run], write_concern: WriteConcern) -> None: ... + def execute(self, write_concern: WriteConcern) -> Union[Dict[str, Any], None]: ... + +class BulkUpsertOperation(object): + def __init__(self, selector: Dict[str, Any], bulk: _Bulk, collation: Collation) -> None: ... + def update_one(self, update: Dict[str, Any]) -> None: ... + def update(self, update: Dict[str, Any]) -> None: ... + def replace_one(self, replacement: Dict[str, Any]) -> None: ... + +class BulkWriteOperation(object): + def __init__(self, selector: Dict[str, Any], bulk: _Bulk, collation: Collation) -> None: ... + def update_one(self, update: Dict[str, Any]) -> None: ... + def update(self, update: Dict[str, Any]) -> None: ... + def replace_one(self, replacement: Dict[str, Any]) -> None: ... + def remove_one(self) -> None: ... + def remove(self) -> None: ... + def upsert(self) -> BulkUpsertOperation: ... + +class BulkOperationBuilder(object): + def __init__(self, collection: Collection, ordered: bool = ..., bypass_document_validation: bool = ...) -> None: ... + def find(self, selector: Dict[str, Any], collation: Optional[Collation] = ...) -> BulkWriteOperation: ... + def insert(self, document: Dict[str, Any]) -> None: ... + def execute(self, write_concern: Optional[WriteConcern] = None) -> Union[Dict[str, Any], None]: ... diff --git a/pymongo/client_options.pyi b/pymongo/client_options.pyi new file mode 100644 index 0000000000..41ef89548b --- /dev/null +++ b/pymongo/client_options.pyi @@ -0,0 +1,44 @@ +from typing import Any, Dict, Optional, Tuple + +from bson.codec_options import CodecOptions +from pymongo.auth import MongoCredential +from pymongo.pool import PoolOptions +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.ssl_support import SSLContext +from pymongo.write_concern import WriteConcern + + +def _parse_credentials(username: str, password: str, database: str, options: Dict[str, Any]) -> Optional[MongoCredential]: ... +def _parse_read_preference(options: Dict[str, Any]) -> _ServerMode: ... +def _parse_write_concern(options: Dict[str, Any]) -> WriteConcern: ... +def _parse_read_concern(options: Dict[str, Any]) -> ReadConcern: ... +def _parse_ssl_options(options: Dict[str, Any]) -> Tuple[Optional[SSLContext], bool]: ... +def _parse_pool_options(options: Dict[str, Any]) -> PoolOptions: ... + +class ClientOptions(object): + def __init__(self, username: str, password: str, database: str, options: Dict[str, Any]) -> None: ... + @property + def _options(self) -> Dict[str, Any]: ... + @property + def connect(self) -> bool: ... + @property + def codec_options(self) -> CodecOptions: ... + @property + def credentials(self) -> MongoCredential: ... + @property + def local_threshold_ms(self) -> int: ... + @property + def server_selection_timeout(self) -> int: ... + @property + def heartbeat_frequency(self) -> int: ... + @property + def pool_options(self) -> PoolOptions: ... + @property + def read_preference(self) -> _ServerMode: ... + @property + def replica_set_name(self) -> Optional[str]: ... + @property + def write_concern(self) -> WriteConcern: ... + @property + def read_concern(self) -> ReadConcern: ... diff --git a/pymongo/collation.pyi b/pymongo/collation.pyi new file mode 100644 index 0000000000..ad3314e032 --- /dev/null +++ b/pymongo/collation.pyi @@ -0,0 +1,27 @@ +from typing import Any, Dict, Optional + + +class CollationStrength(object): + PRIMARY: int = ... + SECONDARY: int = ... + TERTIARY: int = ... + QUATERNARY: int = ... + IDENTICAL: int = ... +class CollationAlternate(object): + NON_IGNORABLE: str = ... + SHIFTED: str = ... +class CollationMaxVariable(object): + PUNCT: str = ... + SPACE: str = ... +class CollationCaseFirst(object): + UPPER: str = ... + LOWER: str = ... + OFF: str = ... +class Collation(object): + def __init__(self, locale: str, caseLevel: Optional[bool] = ..., caseFirst: Optional[str] = ..., strength: Optional[int] = ..., numericOrdering: Optional[bool] = ..., alternate: Optional[str] = ..., maxVariable: Optional[str] = ..., normalization: Optional[bool] = ..., backwards: Optional[bool] = ..., **kwargs: Any) -> None: ... + @property + def document(self) -> Dict[str, Any]: ... + def __repr__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... +def validate_collation_or_none(value: Any) -> Optional[Dict[str, Any]]: ... diff --git a/pymongo/collection.pyi b/pymongo/collection.pyi new file mode 100644 index 0000000000..55abbbac26 --- /dev/null +++ b/pymongo/collection.pyi @@ -0,0 +1,91 @@ +from typing import (Any, Callable, Dict, Iterable, Iterator, List, Mapping, + Optional, Sequence, Tuple, Union) + +from bson.codec_options import CodecOptions +from pymongo.bulk import BulkOperationBuilder +from pymongo.collation import Collation +from pymongo.command_cursor import CommandCursor +from pymongo.common import BaseObject +from pymongo.cursor import Cursor +from pymongo.database import Database +from pymongo.operations import IndexModel, _WriteOp +from pymongo.pool import SocketInfo +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.results import (BulkWriteResult, DeleteResult, InsertManyResult, + InsertOneResult, UpdateResult) +from pymongo.write_concern import WriteConcern + + +class ReturnDocument(object): + BEFORE: bool = ... + AFTER: bool = ... +class Collection(BaseObject): + def __init__(self, database: Database, name: str, create: Optional[bool] = ..., codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ..., **kwargs: Any) -> None: ... + def _socket_for_reads(self) -> Iterator[Tuple[SocketInfo, bool]]: ... + def _socket_for_primary_reads(self) -> Iterator[Tuple[SocketInfo, bool]]: ... + def _socket_for_writes(self) -> Iterator[SocketInfo]: ... + def _command(self, sock_info: SocketInfo, command: Mapping[str, Any], slave_ok: bool = ..., read_preference: Optional[_ServerMode] = ..., codec_options: Optional[CodecOptions] = ..., check: bool = ..., allowable_errors: Optional[Sequence[str]] = ..., read_concern: Optional[ReadConcern] = ..., write_concern: Optional[WriteConcern] = ..., parse_write_concern_error: bool = ..., collation: Optional[Collation] = ...) -> Dict[str, Any]: ... + def __create(self, options: Mapping[str, Any], collation: Collation) -> None: ... + def __getattr__(self, name: str) -> 'Collection': ... + def __getitem__(self, name: str) -> 'Collection': ... + def __repr__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + @property + def full_name(self) -> str: ... + @property + def name(self) -> str: ... + @property + def database(self) -> Database: ... + def with_options(self, codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ...) -> 'Collection': ... + def initialize_unordered_bulk_op(self, bypass_document_validation: bool = ...) -> BulkOperationBuilder: ... + def initialize_ordered_bulk_op(self, bypass_document_validation: bool = ...) -> BulkOperationBuilder: ... + def bulk_write(self, requests: Sequence[_WriteOp], ordered: bool = ..., bypass_document_validation: bool = ...) -> BulkWriteResult: ... + def _legacy_write(self, sock_info: SocketInfo, name: str, cmd: Mapping[str, Any], acknowledged: bool, op_id: int, bypass_doc_val: bool, func: Callable[[Any], Any], *args: Any) -> Dict[str, Any]: ... + def _insert_one(self, sock_info: SocketInfo, doc: Mapping[str, Any], ordered: bool, check_keys: bool, manipulate: bool, write_concern: WriteConcern, op_id: int, bypass_doc_val: bool) -> Any: ... + def _insert(self, sock_info: SocketInfo, docs: Union[Mapping[str, Any], Sequence[Mapping[str, Any]]], ordered: bool = ..., check_keys: bool = ..., manipulate: bool = ..., write_concern: Optional[WriteConcern] = ..., op_id: Optional[int] = ..., bypass_doc_val: bool = ...) -> Any: ... + def insert_one(self, document: Any, bypass_document_validation: bool = ...) -> InsertOneResult: ... + def insert_many(self, documents: Iterable[Any], ordered: bool = ..., bypass_document_validation: bool = ...) -> InsertManyResult: ... + def _update(self, sock_info: SocketInfo, criteria: Mapping[str, Any], document: Mapping[str, Any], upsert: bool = ..., check_keys: bool = ..., multi: bool = ..., manipulate: bool = ..., write_concern: Optional[WriteConcern] = ..., op_id: Optional[int] = ..., ordered: bool = ..., bypass_doc_val: bool = ..., collation: Optional[Collation] = ...) -> Dict[str, Any]: ... + def replace_one(self, filter: Mapping[str, Any], replacement: Mapping[str, Any], upsert: bool = ..., bypass_document_validation: bool = ..., collation: Optional[Collation] = ...) -> UpdateResult: ... + def update_one(self, filter: Mapping[str, Any], update: Mapping[str, Any], upsert: bool = ..., bypass_document_validation: bool = ..., collation: Optional[Collation] = ...) -> UpdateResult: ... + def update_many(self, filter: Mapping[str, Any], update: Mapping[str, Any], upsert: bool = ..., bypass_document_validation: bool = ..., collation: Optional[Collation] = ...) -> UpdateResult: ... + def drop(self) -> None: ... + def _delete(self, sock_info: SocketInfo, criteria: Mapping[str, Any], multi: bool, write_concern: Optional[WriteConcern] = ..., op_id: Optional[int] = ..., ordered: bool = ..., collation: Optional[Collation] = ...) -> Dict[str, Any]: ... + def delete_one(self, filter: Mapping[str, Any], collation: Optional[Collation] = ...) -> DeleteResult: ... + def delete_many(self, filter: Mapping[str, Any], collation: Optional[Collation] = ...) -> DeleteResult: ... + def find_one(self, filter: Optional[Mapping[str, Any]] = ..., *args: Any, **kwargs: Any) -> Optional[Dict[str, Any]]: ... + def find(self, *args: Any, **kwargs: Any) -> Cursor: ... + def parallel_scan(self, num_cursors: int, **kwargs: Any) -> List[CommandCursor]: ... + def _count(self, cmd: Mapping[str, Any], collation: Optional[Collation] = ...) -> int: ... + def count(self, filter: Optional[Mapping[str, Any]] = ..., **kwargs: Any) -> int: ... + def create_indexes(self, indexes: Sequence[IndexModel], **kwargs: Any) -> List[str]: ... + def __create_index(self, keys: Sequence[Tuple[str, Union[int, str]]], index_options: Mapping[str, Any]) -> None: ... + def create_index(self, keys: Union[str, Sequence[Tuple[str, Union[int, str]]]], **kwargs: Any) -> str: ... + def ensure_index(self, key_or_list: Union[str, Sequence[Tuple[str, Union[int, str]]]], cache_for: int = ..., **kwargs: Any) -> Optional[str]: ... + def drop_indexes(self) -> None: ... + def drop_index(self, index_or_name: Union[str, Sequence[Tuple[Any, Any]]]) -> None: ... + def reindex(self) -> Dict[str, Any]: ... + def list_indexes(self) -> CommandCursor: ... + def index_information(self) -> Dict[str, Any]: ... + def options(self) -> Dict[str, Any]: ... + def _aggregate(self, pipeline: Sequence[Mapping[str, Any]], **kwargs: Any) -> CommandCursor: ... + def aggregate(self, pipeline: Sequence[Mapping[str, Any]], **kwargs: Any) -> CommandCursor: ... + def group(self, key: Mapping[str, Any], condition: Mapping[str, Any], initial: Mapping[str, int], reduce: str, finalize: str = ..., **kwargs: Any) -> List[Dict[str, Any]]: ... + def rename(self, new_name: str, **kwargs: Any) -> None: ... + def distinct(self, key: str, filter: Optional[Mapping[str, Any]] = ..., **kwargs: Any) -> List[Any]: ... + def map_reduce(self, map: str, reduce: str, out: Union[str, Mapping[str, Any]], full_response: bool = ..., **kwargs: Any) -> Union[Dict[str, Any], Database, 'Collection']: ... + def inline_map_reduce(self, map: str, reduce: str, full_response: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... + def __find_and_modify(self, filter: Mapping[str, Any], projection: Union[Sequence[str], Mapping[str, bool]], sort: Sequence[Tuple[str, Union[int, str]]], upsert: Optional[bool] = ..., return_document: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... + def find_one_and_delete(self, filter: Mapping[str, Any], projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., **kwargs: Any) -> Dict[str, Any]: ... + def find_one_and_replace(self, filter: Mapping[str, Any], replacement: Mapping[str, Any], projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., upsert: bool = ..., return_document: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... + def find_one_and_update(self, filter: Mapping[str, Any], update: Mapping[str, Any], projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., upsert: bool = ..., return_document: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... + def save(self, to_save: Mapping[str, Any], manipulate: bool = ..., check_keys: bool = ..., **kwargs: Any) -> Any: ... + def insert(self, doc_or_docs: Mapping[str, Any], manipulate: bool = ..., check_keys: bool = ..., continue_on_error: bool = ..., **kwargs: Any) -> Any: ... + def update(self, spec: Mapping[str, Any], document: Mapping[str, Any], upsert: bool = ..., manipulate: bool = ..., multi: bool = ..., check_keys: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... + def remove(self, spec_or_id: Optional[Mapping[str, Any]] = ..., multi: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... + def find_and_modify(self, query: Mapping[str, Any] = {}, update: Mapping[str, Any] = ..., upsert: bool = ..., sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., full_response: bool = ..., manipulate: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... + def __iter__(self) -> 'Collection': ... + def __next__(self) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> None: ... diff --git a/pymongo/command_cursor.pyi b/pymongo/command_cursor.pyi new file mode 100644 index 0000000000..300d42f070 --- /dev/null +++ b/pymongo/command_cursor.pyi @@ -0,0 +1,24 @@ +from typing import Any, Dict, Tuple, Union + +from pymongo import message +from pymongo.collection import Collection + + +class CommandCursor(object): + def __init__(self, collection: Collection, cursor_info: Dict[str, Any], address: Tuple[str, int], retrieved: int = ...) -> None: ... + def __del__(self) -> None: ... + def __die(self) -> None: ... + def close(self) -> None: ... + def batch_size(self, batch_size: int) -> 'CommandCursor': ... + def __send_message(self, operation: Union[message._Query, message._GetMore]) -> None: ... + def _refresh(self) -> int: ... + @property + def alive(self) -> bool: ... + @property + def cursor_id(self) -> int: ... + @property + def address(self) -> Tuple[str, int]: ... + def __iter__(self) -> 'CommandCursor': ... + def next(self) -> Dict[str, Any]: ... + def __enter__(self) -> 'CommandCursor': ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... diff --git a/pymongo/common.pyi b/pymongo/common.pyi new file mode 100644 index 0000000000..78967d2b41 --- /dev/null +++ b/pymongo/common.pyi @@ -0,0 +1,84 @@ +import collections +import datetime +from typing import Any, Callable, Dict, FrozenSet, List, Mapping, Optional, Tuple, Union + +from bson import CodecOptions +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.write_concern import WriteConcern + +MAX_BSON_SIZE: int = ... +MAX_MESSAGE_SIZE: int = ... +MIN_WIRE_VERSION: int = ... +MAX_WIRE_VERSION: int = ... +MAX_WRITE_BATCH_SIZE: int = ... +MIN_SUPPORTED_WIRE_VERSION: int = ... +MAX_SUPPORTED_WIRE_VERSION: int = ... +HEARTBEAT_FREQUENCY: int = ... +KILL_CURSOR_FREQUENCY: int = ... +EVENTS_QUEUE_FREQUENCY: int = ... +SERVER_SELECTION_TIMEOUT: int = ... +MIN_HEARTBEAT_INTERVAL: float = ... +CONNECT_TIMEOUT: float = ... +MAX_POOL_SIZE: int = ... +MIN_POOL_SIZE: int = ... +MAX_IDLE_TIME_MS: Optional[int] = ... +LOCAL_THRESHOLD_MS: int = ... +COMMAND_NOT_FOUND_CODES: Tuple[int, int, None] = ... +UNAUTHORIZED_CODES: Tuple[int, int, int] = ... +_UUID_REPRESENTATIONS: Dict[str, int] = ... +_MECHANISM_PROPS: FrozenSet[str] = ... +_UNICODE_DECODE_ERROR_HANDLERS: FrozenSet[str] = ... +WRITE_CONCERN_OPTIONS: FrozenSet[str] = ... +def partition_node(node: str) -> Tuple[str, int]: ... +def clean_node(node: str) -> Tuple[str, int]: ... +def raise_config_error(key: str, dummy: Any) -> None: ... +def validate_boolean(option: str, value: Any) -> bool: ... +def validate_boolean_or_string(option: str, value: Any) -> bool: ... +def validate_integer(option: str, value: Any) -> int: ... +def validate_positive_integer(option: str, value: Any) -> int: ... +def validate_non_negative_integer(option: str, value: Any) -> int: ... +def validate_readable(option: str, value: Any) -> Optional[str]: ... +def validate_positive_integer_or_none(option: str, value: Any) -> Optional[int]: ... +def validate_non_negative_integer_or_none(option: str, value: Any) -> Optional[int]: ... +def validate_string(option: str, value: Any) -> str: ... +def validate_string_or_none(option: str, value: Any) -> Optional[str]: ... +def validate_int_or_basestring(option: str, value: Any) -> Union[int, str]: ... +def validate_positive_float(option: str, value: Any) -> float: ... +def validate_positive_float_or_zero(option: str, value: Any) -> float: ... +def validate_timeout_or_none(option: str, value: Any) -> Optional[float]: ... +def validate_timeout_or_zero(option: str, value: Any) -> float: ... +def validate_max_staleness(option: str, value: Any) -> int: ... +def validate_read_preference(dummy: Any, value: Any) -> _ServerMode: ... +def validate_read_preference_mode(dummy: Any, value: Any) -> _ServerMode: ... +def validate_auth_mechanism(option: str, value: Any) -> str: ... +def validate_uuid_representation(dummy: Any, value: Any) -> int: ... +def validate_read_preference_tags(name: str, value: Any) -> List[Dict[str, str]]: ... +def validate_auth_mechanism_properties(option: str, value: Any) -> Dict[str, Union[bool, str]]: ... +def validate_document_class(option: str, value: Any) -> Union[collections.MutableMapping, collections.Mapping]: ... +def validate_list(option: str, value: Any) -> List[Any]: ... +def validate_is_mapping(option: str, value: Any) -> Dict[Any, Any]: ... +def validate_is_document_type(option: str, value: Any) -> None: ... +def validate_appname_or_none(option: str, value: Any) -> Optional[str]: ... +def validate_ok_for_replace(replacement: Any) -> None: ... +def validate_ok_for_update(update: Any) -> None: ... +def validate_unicode_decode_error_handler(dummy: Any, value: str) -> str: ... +def validate_tzinfo(dummy: Any, value: Any) -> Optional[datetime.tzinfo]: ... +URI_VALIDATORS: Dict[str, Callable[..., Any]] = ... +TIMEOUT_VALIDATORS: Dict[str, Callable[..., Any]] = ... +KW_VALIDATORS: Dict[str, Callable[..., Any]] = ... +VALIDATORS: Dict[str, Callable[..., Any]] = ... +_AUTH_OPTIONS: FrozenSet[str] = ... +def validate_auth_option(option: str, value: Any) -> Tuple[str, Any]: ... +def validate(option: str, value: Any) -> Tuple[str, Any]: ... +def get_validated_options(options: Mapping[str, Any], warn: bool = True) -> Dict[str, Any]: ... +class BaseObject(object): + def __init__(self, codec_options: CodecOptions, read_preference: _ServerMode, write_concern: WriteConcern, read_concern: ReadConcern) -> None: ... + @property + def codec_options(self) -> CodecOptions: ... + @property + def write_concern(self) -> WriteConcern: ... + @property + def read_preference(self) -> _ServerMode: ... + @property + def read_concern(self) -> ReadConcern: ... diff --git a/pymongo/cursor.pyi b/pymongo/cursor.pyi new file mode 100644 index 0000000000..e564c7ad0c --- /dev/null +++ b/pymongo/cursor.pyi @@ -0,0 +1,68 @@ +from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union + +from pymongo.collation import Collation +from pymongo.collection import Collection +from pymongo.message import _GetMore, _Query +from pymongo.pool import Pool, SocketInfo + +_QUERY_OPTIONS: Dict[str, int] = ... +class CursorType(object): + NON_TAILABLE: int = ... + TAILABLE: int = ... + TAILABLE_AWAIT: int = ... + EXHAUST: int = ... + +class _SocketManager: + def __init__(self, sock: SocketInfo, pool: Pool) -> None: ... + def __del__(self) -> None: ... + def close(self) -> None: ... + +class Cursor(object): + def __init__(self, collection: Collection, filter: Mapping[str, Any] = ..., projection: Mapping[str, Any] = ..., skip: int = ..., limit: int = ..., no_cursor_timeout: bool = ..., cursor_type: int = ..., sort: Optional[Sequence[Tuple[str, Any]]] = ..., allow_partial_results: bool = ..., oplog_replay: bool = ..., modifiers: Optional[Mapping[str, Any]] = ..., batch_size: int = ..., manipulate: bool = ..., collation: Optional[Mapping[str, Any]] = ...) -> None: ... + @property + def collection(self) -> Collection: ... + @property + def retrieved(self) -> int: ... + def __del__(self) -> None: ... + def rewind(self) -> 'Cursor': ... + def clone(self) -> 'Cursor': ... + def _clone(self, deepcopy: bool = ...) -> 'Cursor': ... + def _clone_base(self) -> 'Cursor': ... + def __die(self, synchronous: bool = ...) -> None: ... + def close(self) -> None: ... + def __query_spec(self) -> Dict[str, Any]: ... + def __check_okay_to_chain(self) -> None: ... + def add_option(self, mask: int) -> 'Cursor': ... + def remove_option(self, mask: int) -> 'Cursor': ... + def limit(self, limit: int) -> 'Cursor': ... + def batch_size(self, batch_size: int) -> 'Cursor': ... + def skip(self, skip: int) -> 'Cursor': ... + def max_time_ms(self, max_time_ms: int) -> 'Cursor': ... + def max_await_time_ms(self, max_await_time_ms: int) -> 'Cursor': ... + def __getitem__(self, index: Union[int, Sequence[int]]) -> Union['Cursor', Dict[str, Any]]: ... + def max_scan(self, max_scan: int) -> 'Cursor': ... + def max(self, spec: Sequence[Tuple[str, int]]) -> 'Cursor': ... + def min(self, spec: Sequence[Tuple[str, int]]) -> 'Cursor': ... + def sort(self, key_or_list: Union[str, Sequence[Tuple[str, Union[int, str]]]], direction: Optional[Union[int, str]] = ...) -> 'Cursor': ... + def count(self, with_limit_and_skip: bool = ...) -> int: ... + def distinct(self, key: str) -> List[Any]: ... + def explain(self) -> Dict[str, Any]: ... + def hint(self, index: Union[str, Tuple[str, Union[int, str]]]): ... + def comment(self, comment: Union[str, Mapping[str, Any]]) -> 'Cursor': ... + def where(self, code: str) -> 'Cursor': ... + def collation(self, collation: Collation) -> 'Cursor': ... + def __send_message(self, operation: Union[None, _GetMore, _Query]) -> None: ... + def _refresh(self) -> int: ... + @property + def alive(self) -> bool: ... + @property + def cursor_id(self) -> int: ... + @property + def address(self) -> Tuple[str, int]: ... + def __iter__(self) -> 'Cursor': ... + def next(self) -> Dict[str, Any]: ... + def __enter__(self) -> 'Cursor': ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... + def __copy__(self) -> 'Cursor': ... + def __deepcopy__(self, memo: Any) -> 'Cursor': ... + def _deepcopy(self, x: Mapping[str, Any], memo: Optional[Mapping[int, Any]] = ...) -> Union[List[Any], Dict[Any, Any]]: ... diff --git a/pymongo/cursor_manager.pyi b/pymongo/cursor_manager.pyi new file mode 100644 index 0000000000..a6df6e48f9 --- /dev/null +++ b/pymongo/cursor_manager.pyi @@ -0,0 +1,8 @@ +from typing import Tuple + +from pymongo import MongoClient + + +class CursorManager(object): + def __init__(self, client: MongoClient) -> None: ... + def close(self, cursor_id: int, address: Tuple[str, int]) -> None: ... diff --git a/pymongo/database.pyi b/pymongo/database.pyi new file mode 100644 index 0000000000..8daaadf45e --- /dev/null +++ b/pymongo/database.pyi @@ -0,0 +1,80 @@ +from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Union + +from bson import CodecOptions, DBRef +from pymongo import MongoClient, common +from pymongo.collection import Collection +from pymongo.command_cursor import CommandCursor +from pymongo.pool import SocketInfo +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.son_manipulator import SONManipulator +from pymongo.write_concern import WriteConcern + + +def _check_name(name: str) -> None: ... + +class Database(common.BaseObject): + def __init__(self, client: MongoClient, name: str, codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ...) -> None: ... + def add_son_manipulator(self, manipulator: SONManipulator): ... + @property + def system_js(self) -> SystemJS: ... + @property + def client(self) -> MongoClient: ... + @property + def name(self) -> str: ... + @property + def incoming_manipulators(self) -> List[str]: ... + @property + def incoming_copying_manipulators(self) -> List[str]: ... + @property + def outgoing_manipulators(self) -> List[str]: ... + @property + def outgoing_copying_manipulators(self) -> List[str]: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __repr__(self) -> str: ... + def __getattr__(self, name: str) -> Collection: ... + def __getitem__(self, name: str) -> Collection: ... + def get_collection(self, name: str, codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ...) -> Collection: ... + def _collection_default_options(self, name: str, **kargs: Any) -> Collection: ... + def create_collection(self, name: str, codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ..., **kwargs: Any) -> Collection: ... + def _apply_incoming_manipulators(self, son: Mapping[str, Any], collection: Collection) -> Mapping[str, Any]: ... + def _apply_incoming_copying_manipulators(self, son: Mapping[str, Any], collection: Collection) -> Mapping[str, Any]: ... + def _fix_incoming(self, son: Mapping[str, Any], collection: Collection) -> Mapping[str, Any]: ... + def _fix_outgoing(self, son: Mapping[str, Any], collection: Collection) -> Mapping[str, Any]: ... + def _command(self, sock_info: SocketInfo, command: Union[str, Mapping[str, Any]], slave_ok: bool = ..., value: int = ..., check: bool = ..., allowable_errors: Optional[Sequence[str]] = ..., read_preference: _ServerMode = ..., codec_options: CodecOptions = ..., write_concern: Optional[WriteConcern] = ..., parse_write_concern_error: bool = ..., **kwargs: Any) -> Any: ... + def command(self, command: Union[str, Mapping[str, Any]], value: int = ..., check: bool = ..., allowable_errors: Optional[Sequence[str]] = ..., read_preference: _ServerMode = ..., codec_options: CodecOptions = ..., **kwargs: Any) -> Any: ... + def _list_collections(self, sock_info: SocketInfo, slave_okay: bool, criteria: Mapping[str, Any] = ...) -> CommandCursor: ... + def collection_names(self, include_system_collections: bool = ...) -> List[str]: ... + def drop_collection(self, name_or_collection: Union[str, Collection]) -> Dict[str, Any]: ... + def validate_collection(self, name_or_collection: Union[str, Collection], scandata: bool = ..., full: bool = ...) -> Dict[str, Any]: ... + def current_op(self, include_all: bool = ...) -> Dict[str, Any]: ... + def profiling_level(self) -> int: ... + def set_profiling_level(self, level: int, slow_ms: Optional[int] = ...) -> None: ... + def profiling_info(self) -> List[Any]: ... + def error(self) -> Any: ... + def last_status(self) -> Any: ... + def previous_error(self) -> Any: ... + def reset_error_history(self) -> None: ... + def __iter__(self) -> 'Database': ... + def __next__(self) -> None: ... + def _default_role(self, read_only: bool) -> str: ... + def _create_or_update_user(self, create: bool, name: str, password: str, read_only: bool, **kwargs: Any) -> None: ... + def _legacy_add_user(self, name: str, password: str, read_only: bool, **kwargs: Any) -> None: ... + def add_user(self, name: str, password: Optional[str] = ..., read_only: Optional[bool] = ..., **kwargs: Any) -> None: ... + def remove_user(self, name: str) -> None: ... + def authenticate(self, name: Optional[str] = ..., password: Optional[str] = ..., source: Optional[str] = ..., mechanism: str = ..., **kwargs: Any) -> bool: ... + def logout(self) -> None: ... + def dereference(self, dbref: DBRef, **kwargs: Any) -> Dict[str, Any]: ... + def eval(self, code: str, *args: Any) -> Any: ... + def __call__(self, *args: Any, **kwargs: Any): ... + +class SystemJS(object): + def __init__(self, database: Database) -> None: ... + def __setattr__(self, name: str, code: str) -> None: ... + def __setitem__(self, name: str, code: str) -> None: ... + def __delattr__(self, name: str) -> None: ... + def __delitem__(self, name: str) -> None: ... + def __getattr__(self, name: str) -> Callable[..., Any]: ... + def __getitem__(self, name: str) -> Callable[..., Any]: ... + def list(self) -> List[str]: ... diff --git a/pymongo/errors.pyi b/pymongo/errors.pyi new file mode 100644 index 0000000000..427eb06082 --- /dev/null +++ b/pymongo/errors.pyi @@ -0,0 +1,33 @@ +from bson.errors import InvalidDocument + +from typing import Any, Dict, Mapping, Optional + +class PyMongoError(Exception): ... +class ProtocolError(PyMongoError): ... +class ConnectionFailure(PyMongoError): ... +class AutoReconnect(ConnectionFailure): + def __init__(self, message: str = '', errors: Any = None) -> None: ... +class NetworkTimeout(AutoReconnect): ... +class NotMasterError(AutoReconnect): ... +class ServerSelectionTimeoutError(AutoReconnect): ... +class ConfigurationError(PyMongoError): ... +class OperationFailure(PyMongoError): + def __init__(self, error: str, code: Optional[int] = None, details: Optional[Mapping[str, Any]] = None) -> None: ... + @property + def code(self) -> int: ... + @property + def details(self) -> Dict[str, Any]: ... +class CursorNotFound(OperationFailure): ... +class ExecutionTimeout(OperationFailure): ... +class WriteConcernError(OperationFailure): ... +class WriteError(OperationFailure): ... +class WTimeoutError(WriteConcernError): ... +class DuplicateKeyError(WriteError): ... +class BulkWriteError(OperationFailure): + def __init__(self, results: Mapping[str, Any]) -> None: ... +class InvalidOperation(PyMongoError): ... +class InvalidName(PyMongoError): ... +class CollectionInvalid(PyMongoError): ... +class InvalidURI(ConfigurationError): ... +class ExceededMaxWaiters(Exception): ... +class DocumentTooLarge(InvalidDocument): ... diff --git a/pymongo/helpers.pyi b/pymongo/helpers.pyi new file mode 100644 index 0000000000..46bdb66915 --- /dev/null +++ b/pymongo/helpers.pyi @@ -0,0 +1,21 @@ +from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union + +from bson import CodecOptions +from pymongo.collection import Collection +from pymongo.database import Database +from pymongo.monitoring import _EventListeners +from pymongo.pool import SocketInfo +from pymongo.read_preferences import _ServerMode + + +_UUNDER: str = ... +_UNICODE_REPLACE_CODEC_OPTIONS: CodecOptions = ... +def _gen_index_name(keys: Sequence[Tuple[Any, Any]]) -> str: ... +def _index_list(key_or_list: Union[str, Sequence[Tuple[str, Union[int, str]]]], direction: Optional[Union[int, str]] = ...) -> List[Tuple[str, Union[int, str]]]: ... +def _index_document(index_list: Sequence[Tuple[str, Union[int, str]]]) -> Mapping[str, Any]: ... +def _unpack_response(response: bytes, cursor_id: Optional[int] = ..., codec_options: CodecOptions = ...) -> Dict[str, Any]: ... +def _check_command_response(response: bytes, msg: Optional[str] = ..., allowable_errors: Optional[Sequence[str]] = ..., parse_write_concern_error: bool = ...) -> None: ... +def _check_gle_response(response: bytes) -> Dict[str, Any]: ... +def _first_batch(sock_info: SocketInfo, db: Database, coll: Collection, query: Mapping[str, Any], ntoreturn: int, slave_ok: bool, codec_options: CodecOptions, read_preference: _ServerMode, cmd: Mapping[str, Any], listeners: _EventListeners) -> Dict[str, Any]: ... +def _check_write_command_response(results: Mapping[str, Any]) -> None: ... +def _fields_list_to_dict(fields: Sequence[str], option_name: str) -> Dict[str, int]: ... diff --git a/pymongo/ismaster.pyi b/pymongo/ismaster.pyi new file mode 100644 index 0000000000..1be35fb708 --- /dev/null +++ b/pymongo/ismaster.pyi @@ -0,0 +1,40 @@ +from typing import Any, Dict, List, Mapping, Optional, Tuple + + +def _get_server_type(doc: Mapping[str, Any]) -> int: ... +class IsMaster(object): + def __init__(self, doc: Mapping[str, Any]) -> None: ... + @property + def document(self) -> Dict[str, Any]: ... + @property + def server_type(self) -> int: ... + @property + def all_hosts(self) -> List[Any]: ... + @property + def tags(self) -> Dict[str, Any]: ... + @property + def primary(self) -> Optional[Tuple[str, int]]: ... + @property + def replica_set_name(self) -> Optional[str]: ... + @property + def max_bson_size(self) -> int: ... + @property + def max_message_size(self) -> int: ... + @property + def max_write_batch_size(self) -> int: ... + @property + def min_wire_version(self) -> int: ... + @property + def max_wire_version(self) -> int: ... + @property + def set_version(self) -> Any: ... + @property + def election_id(self) -> Any: ... + @property + def is_writable(self) -> bool: ... + @property + def is_readable(self) -> bool: ... + @property + def me(self) -> Optional[Tuple[str, int]]: ... + @property + def last_write_date(self) -> Any: ... diff --git a/pymongo/max_staleness_selectors.pyi b/pymongo/max_staleness_selectors.pyi new file mode 100644 index 0000000000..ea56715b6b --- /dev/null +++ b/pymongo/max_staleness_selectors.pyi @@ -0,0 +1,9 @@ +from pymongo.server_selectors import Selection + + +IDLE_WRITE_PERIOD: int = ... +SMALLEST_MAX_STALENESS: int = ... +def _validate_max_staleness(max_staleness: int, heartbeat_frequency: int) -> None: ... +def _with_primary(max_staleness: int, selection: Selection) -> Selection: ... +def _no_primary(max_staleness: int, selection: Selection) -> Selection: ... +def select(max_staleness: int, selection: Selection) -> Selection: ... diff --git a/pymongo/message.pyi b/pymongo/message.pyi new file mode 100644 index 0000000000..f7f263b62f --- /dev/null +++ b/pymongo/message.pyi @@ -0,0 +1,81 @@ +import datetime +from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union + +from bson import CodecOptions +from pymongo.database import Database +from pymongo.collection import Collection +from pymongo.collation import Collation +from pymongo.monitoring import _EventListeners +from pymongo.pool import SocketInfo +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode + +MAX_INT32: int = ... +MIN_INT32: int = ... +_COMMAND_OVERHEAD: int = ... +_INSERT: int = ... +_UPDATE: int = ... +_DELETE: int = ... +_EMPTY: bytes = ... +_BSONOBJ: bytes = ... +_ZERO_8: bytes = ... +_ZERO_16: bytes = ... +_ZERO_32: bytes = ... +_ZERO_64: bytes = ... +_SKIPLIM: bytes = ... +_OP_MAP: Dict[int, bytes] = ... +_UJOIN: str = ... +def _randint() -> int: ... +def _maybe_add_read_preference(spec: Mapping[str, Any], read_preference: _ServerMode) -> Dict[str, Any]: ... +def _convert_exception(exception: Exception) -> Dict[str, str]: ... +def _convert_write_result(operation: Union[_Query, _GetMore], command: Mapping[str, Any], result: Mapping[str, Any]) -> Dict[str, Any]: ... +_OPTIONS: Mapping[str, Any] = ... +_MODIFIERS: Mapping[str, Any] = ... +def _gen_explain_command(coll: Collection, spec: Mapping[str, Any], projection: Union[Mapping[str, bool], Sequence[str]], skip: int, limit: int, batch_size: int, options: bool, read_concern: ReadConcern) -> Dict[str, Any]: ... +def _gen_find_command(coll: Collection, spec: Mapping[str, Any], projection: Union[Mapping[str, bool], Sequence[str]], skip: int, limit: int, batch_size: int, options: bool, read_concern: ReadConcern = ..., collation: Optional[Collation] = ...) -> Dict[str, Any]: ... +def _gen_get_more_command(cursor_id: int, coll: Collection, batch_size: int, max_await_time_ms: int) -> Dict[str, Any]: ... + +class _Query(object): + def __init__(self, flags: bool, db: Database, coll: Collection, ntoskip: int, spec: Mapping[str, Any], fields: Union[Mapping[str, bool], Sequence[str]], codec_options: CodecOptions, read_preference: _ServerMode, limit: int, batch_size: int, read_concern: ReadConcern, collation: Collation) -> None: ... + def as_command(self) -> Dict[str, Any]: ... + def get_message(self, set_slave_ok: bool, is_mongos: bool, use_cmd: bool = ...) -> Tuple[int, bytes, int]: ... + +class _GetMore(object): + def __init__(self, db: Database, coll: Collection, ntoreturn: int, cursor_id: int, codec_options: CodecOptions, max_await_time_ms: Optional[int] = ...) -> None: ... + def as_command(self) -> Mapping[str, Any]: ... + def get_message(self, dummy0: Any, dummy1: Any, use_cmd: bool = ...) -> Tuple[Any]: ... + +class _CursorAddress(tuple): + def __new__(cls, address: Tuple[str, int], namespace: Any) -> '_CursorAddress': ... + @property + def namespace(self) -> Any: ... + def __hash__(self) -> int: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + +def __last_error(namespace: str, args: Dict[str, Any]) -> Tuple[int, bytes, int]: ... +def __pack_message(operation: Union[_Query, _GetMore], data: bytes) -> Tuple[int, bytes]: ... +def insert(collection_name: str, docs: Mapping[str, Any], check_keys: bool, safe: bool, last_error_args: Mapping[str, Any], continue_on_error: bool, opts: CodecOptions) -> Tuple[int, bytes, int]: ... +def update(collection_name: str, upsert: bool, multi: bool, spec: Mapping[str, Any], doc: Mapping[str, Any], safe: bool, last_error_args: Mapping[str, Any], check_keys: bool, opts: CodecOptions) -> Tuple[int, bytes, int]: ... +def query(options: int, collection_name: str, num_to_skip: int, num_to_return: int, query: Mapping[str, Any], field_selector: Mapping[str, Any], opts: CodecOptions, check_keys: bool = ...) -> Tuple[int, bytes, int]: ... +def get_more(collection_name: str, num_to_return: int, cursor_id: int) -> Tuple[int, bytes]: ... +def delete(collection_name: str, spec: Mapping[str, Any], safe: bool, last_error_args: Mapping[str, Any], opts: CodecOptions, flags: int = 0) -> Tuple[int, bytes, int]: ... +def kill_cursors(cursor_ids: Sequence[int]) -> Tuple[int, bytes]: ... +_FIELD_MAP: Dict[str, str] = ... + +class _BulkWriteContext(object): + def __init__(self, database_name: str, command: Mapping[str, Any], sock_info: SocketInfo, operation_id: int, listeners: _EventListeners) -> None: ... + @property + def max_bson_size(self) -> int: ... + @property + def max_message_size(self) -> int: ... + @property + def max_write_batch_size(self) -> int: ... + def legacy_write(self, request_id: int, msg: bytes, max_doc_size: int, acknowledged: bool, docs: Sequence[Mapping[str, Any]]) -> Dict[str, Any]: ... + def write_command(self, request_id: int, msg: bytes, docs: Sequence[Mapping[str, Any]]) -> Dict[str, Any]: ... + def _start(self, request_id: int, docs: Sequence[Mapping[str, Any]]) -> Dict[str, Any]: ... + def _succeed(self, request_id: int, reply: Mapping[str, Any], duration: datetime.timedelta) -> None: ... + def _fail(self, request_id: int, failure: Mapping[str, Any], duration: datetime.timedelta) -> None: ... +def _raise_document_too_large(operation: str, doc_size: int, max_size: int) -> None: ... +def _do_batched_insert(collection_name: str, docs: Sequence[Mapping[str, Any]], check_keys: bool, safe: bool, last_error_args: Mapping[str, Any], continue_on_error: bool, opts: CodecOptions, ctx: _BulkWriteContext) -> None: ... +def _do_batched_write_command(namespace: str, operation: int, command: Mapping[str, Any], docs: Sequence[Mapping[str, Any]], check_keys: bool, opts: CodecOptions, ctx: _BulkWriteContext) -> None: ... diff --git a/pymongo/mongo_client.pyi b/pymongo/mongo_client.pyi new file mode 100644 index 0000000000..e2437383e9 --- /dev/null +++ b/pymongo/mongo_client.pyi @@ -0,0 +1,100 @@ +import contextlib +from typing import (Any, Callable, Dict, FrozenSet, List, Optional, + Set, Sequence, Tuple, Type, Union) + +from bson import CodecOptions +from pymongo.auth import MongoCredential +from pymongo.common import BaseObject +from pymongo.cursor_manager import CursorManager +from pymongo.database import Database +from pymongo.message import _CursorAddress, _GetMore, _Query +from pymongo.monitoring import _EventListeners +from pymongo.pool import SocketInfo +from pymongo.topology import Topology +from pymongo.write_concern import WriteConcern +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.response import Response +from pymongo.server import Server + +class MongoClient(BaseObject): + HOST: str = ... + PORT: int = ... + def __init__(self, host: str = ..., port: int = ..., document_class: Type[Any] = ..., tz_aware: Optional[bool] = ..., connect: Optional[bool] = ..., **kwargs: Any) -> None: ... + def _cache_credentials(self, source: str, credentials: MongoCredential, connect: bool = ...) -> None: ... + def _purge_credentials(self, source: str) -> None: ... + def _cached(self, dbname: str, coll: str, index: Union[str, int]) -> bool: ... + def _cache_index(self, dbname: str, collection: str, index: Union[str, int], cache_for: int) -> None: ... + def _purge_index(self, database_name: str, collection_name: Optional[str] = ..., index_name: Optional[str] = ...) -> None: ... + def _server_property(self, attr_name: str) -> Any: ... + @property + def event_listeners(self) -> _EventListeners: ... + @property + def address(self) -> Union[Tuple[str, int], None]: ... + @property + def primary(self) -> Union[Tuple[str, int], None]: ... + @property + def secondaries(self) -> Union[Set[str], Set[Tuple[str, int]]]: ... + @property + def arbiters(self) -> Union[Set[str], Set[Tuple[str, int]]]: ... + @property + def is_primary(self) -> bool: ... + @property + def is_mongos(self) -> bool: ... + @property + def max_pool_size(self) -> int: ... + @property + def min_pool_size(self) -> int: ... + @property + def max_idle_time_ms(self) -> int: ... + @property + def nodes(self) -> FrozenSet[Tuple[str, int]]: ... + @property + def max_bson_size(self) -> int: ... + @property + def max_message_size(self) -> int: ... + @property + def max_write_batch_size(self) -> int: ... + @property + def local_threshold_ms(self) -> int: ... + @property + def server_selection_timeout(self) -> int: ... + @property + def _is_writable(self) -> bool: ... + def close(self) -> None: ... + def set_cursor_manager(self, manager_class: CursorManager) -> None: ... + def _get_topology(self) -> Topology: ... + @contextlib.contextmanager + def _get_socket(self, selector: Callable[[Sequence[Server]], Sequence[Server]]) -> None: ... + def _socket_for_writes(self) -> SocketInfo: ... + @contextlib.contextmanager + def _socket_for_reads(self, read_preference: _ServerMode) -> Tuple[SocketInfo, bool]: ... + def _send_message_with_response(self, operation: Union[_Query, _GetMore], read_preference: Optional[_ServerMode] = ..., exhaust: bool = ..., address: Optional[Tuple[str, int]] = ...) -> Response: ... + def _reset_on_error(self, server: Server, func: Callable[[Any], Any], *args: Any, **kwargs: Any) -> Any: ... + def __reset_server(self, address: Tuple[str, int]) -> None: ... + def _reset_server_and_request_check(self, address: Tuple[str, int]) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def _repr_helper(self) -> str: ... + def __repr__(self) -> str: ... + def __getattr__(self, name: str) -> Database: ... + def __getitem__(self, name: str) -> Database: ... + def close_cursor(self, cursor_id: int, address: Optional[Tuple[str, int]] = ...) -> None: ... + def _close_cursor_now(self, cursor_id: int, address: Optional[Tuple[str, int]] = ...) -> None: ... + def kill_cursors(self, cursor_ids: Sequence[int], address: Optional[Tuple[str, int]] = ...) -> None: ... + def _kill_cursors(self, cursor_ids: Sequence[int], address: Union[Tuple[str, int], _CursorAddress], topology: Topology) -> None: ... + def _process_periodic_tasks(self) -> None: ... + def server_info(self) -> Dict[str, Any]: ... + def database_names(self) -> List[str]: ... + def drop_database(self, name_or_database: Union[str, Database]) -> None: ... + def get_default_database(self) -> Database: ... + def get_database(self, name: Optional[str] = ..., codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ...) -> Database: ... + def _database_default_options(self, name: str) -> Database: ... + @property + def is_locked(self) -> bool: ... + def fsync(self, **kwargs: Any) -> Dict[str, Any]: ... + def unlock(self) -> None: ... + def __enter__(self) -> 'MongoClient': ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... + def __iter__(self) -> 'MongoClient': ... + def __next__(self) -> None: ... diff --git a/pymongo/mongo_replica_set_client.pyi b/pymongo/mongo_replica_set_client.pyi new file mode 100644 index 0000000000..4625ed1e89 --- /dev/null +++ b/pymongo/mongo_replica_set_client.pyi @@ -0,0 +1,8 @@ +from typing import Any + +from pymongo import mongo_client + + +class MongoReplicaSetClient(mongo_client.MongoClient): + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def __repr__(self) -> str: ... diff --git a/pymongo/monitor.pyi b/pymongo/monitor.pyi new file mode 100644 index 0000000000..ba05b0b23c --- /dev/null +++ b/pymongo/monitor.pyi @@ -0,0 +1,19 @@ +from typing import Any, Optional, Tuple + +from pymongo.ismaster import IsMaster +from pymongo.pool import Pool, SocketInfo +from pymongo.server_description import ServerDescription +from pymongo.settings import TopologySettings +from pymongo.topology import Topology + + +class Monitor(object): + def __init__(self, server_description: ServerDescription, topology: Topology, pool: Pool, topology_settings: TopologySettings) -> None: ... + def open(self) -> None: ... + def close(self) -> None: ... + def join(self, timeout: int = None) -> None: ... + def request_check(self) -> None: ... + def _run(self) -> None: ... + def _check_with_retry(self) -> ServerDescription: ... + def _check_once(self, metadata: Optional[Any] = None) -> ServerDescription: ... + def _check_with_socket(self, sock_info: SocketInfo, metadata: Optional[Any] = None) -> Tuple[IsMaster, int]: ... diff --git a/pymongo/monitoring.pyi b/pymongo/monitoring.pyi new file mode 100644 index 0000000000..b5d18f6b6b --- /dev/null +++ b/pymongo/monitoring.pyi @@ -0,0 +1,154 @@ +from typing import (Any, Dict, Mapping, NamedTuple, Optional, Set, Sequence, + Tuple, Union) +import datetime + +from pymongo.ismaster import IsMaster +from pymongo.server_description import ServerDescription + + +class _Listeners(NamedTuple): + command_listeners: Sequence[CommandListener] + server_listeners: Sequence[ServerListener] + server_heartbeat_listeners: Sequence[ServerHeartbeatListener] + topology_listeners: Sequence[TopologyListener] + +_LISTENERS: _Listeners = ... + +class _EventListener(object): ... + +class CommandListener(_EventListener): + def started(self, event: CommandStartedEvent) -> None: ... + def succeeded(self, event: CommandSucceededEvent) -> None: ... + def failed(self, event: CommandFailedEvent) -> None: ... + +class ServerHeartbeatListener(_EventListener): + def started(self, event: ServerHeartbeatStartedEvent) -> None: ... + def succeeded(self, event: ServerHeartbeatSucceededEvent) -> None: ... + def failed(self, event: ServerHeartbeatFailedEvent) -> None: ... + +class TopologyListener(_EventListener): + def opened(self, event: TopologyOpenedEvent) -> None: ... + def description_changed(self, event: TopologyDescriptionChangedEvent) -> None: ... + def closed(self, event: TopologyClosedEvent) -> None: ... + +class ServerListener(_EventListener): + def opened(self, event: ServerOpeningEvent) -> None: ... + def description_changed(self, event: ServerDescriptionChangedEvent) -> None: ... + def closed(self, event: ServerClosedEvent) -> None: ... + +def _to_micros(dur: datetime.timedelta) -> int: ... +def _validate_event_listeners(option: str, listeners: Sequence[_EventListener]) -> Sequence[_EventListener]: ... +def register(listener: _EventListener) -> None: ... +_SENSITIVE_COMMANDS: Set[str] = ... + +class _CommandEvent(object): + def __init__(self, command_name: str, request_id: int, connection_id: Tuple[str, int], operation_id: int) -> None: ... + @property + def command_name(self) -> str: ... + @property + def request_id(self) -> int: ... + @property + def connection_id(self) -> Tuple[str, int]: ... + @property + def operation_id(self) -> int: ... + +class CommandStartedEvent(_CommandEvent): + def __init__(self, command: Mapping[str, Any], database_name: str, *args: Any) -> None: ... + @property + def command(self) -> Dict[str, Any]: ... + @property + def database_name(self) -> str: ... + +class CommandSucceededEvent(_CommandEvent): + def __init__(self, duration: datetime.timedelta, reply: Mapping[str, Any], command_name: str, request_id: int, connection_id: Tuple[str, int], operation_id: int) -> None: ... + @property + def duration_micros(self) -> int: ... + @property + def reply(self) -> Dict[str, Any]: ... + +class CommandFailedEvent(_CommandEvent): + def __init__(self, duration: datetime.timedelta, failure: Mapping[str, Any], *args: Any) -> None: ... + @property + def duration_micros(self) -> int: ... + @property + def failure(self) -> Dict[str, Any]: ... + +class _ServerEvent(object): + def __init__(self, server_address: Tuple[str, int], topology_id: int) -> None: ... + @property + def server_address(self) -> Tuple[str, int]: ... + @property + def topology_id(self) -> int: ... + +class ServerDescriptionChangedEvent(_ServerEvent): + def __init__(self, previous_description: ServerDescription, new_description: ServerDescription, *args: Any) -> None: ... + @property + def previous_description(self) -> ServerDescription: ... + @property + def new_description(self) -> ServerDescription: ... + +class ServerOpeningEvent(_ServerEvent): ... + +class ServerClosedEvent(_ServerEvent): ... + +class TopologyEvent(object): + def __init__(self, topology_id: int) -> None: ... + @property + def topology_id(self) -> int: ... + +class TopologyDescriptionChangedEvent(TopologyEvent): + def __init__(self, previous_description: ServerDescription, + new_description: ServerDescription, *args: Any) -> None: ... + @property + def previous_description(self) -> ServerDescription: ... + @property + def new_description(self) -> ServerDescription: ... + +class TopologyOpenedEvent(TopologyEvent): ... + +class TopologyClosedEvent(TopologyEvent): ... + +class _ServerHeartbeatEvent(object): + def __init__(self, connection_id: Tuple[str, int]) -> None: ... + @property + def connection_id(self) -> Tuple[str, int]: ... + +class ServerHeartbeatStartedEvent(_ServerHeartbeatEvent): ... + +class ServerHeartbeatSucceededEvent(_ServerHeartbeatEvent): + def __init__(self, duration: int, reply: IsMaster, *args: Any) -> None: ... + @property + def duration(self) -> int: ... + @property + def reply(self) -> IsMaster: ... + +class ServerHeartbeatFailedEvent(_ServerHeartbeatEvent): + def __init__(self, duration: int, reply: Exception, *args: Any) -> None: ... + @property + def duration(self) -> int: ... + @property + def reply(self) -> Exception: ... + +class _EventListeners(object): + def __init__(self, listeners: Sequence[_EventListener]) -> None: ... + @property + def enabled_for_commands(self) -> bool: ... + @property + def enabled_for_server(self) -> bool: ... + @property + def enabled_for_server_heartbeat(self) -> bool: ... + @property + def enabled_for_topology(self) -> bool: ... + def event_listeners(self) -> Tuple[Sequence[Any]]: ... + def publish_command_start(self, command: Mapping[str, Any], database_name: str, request_id: int, connection_id: Tuple[str, int], op_id: Optional[int] = ...) -> None: ... + def publish_command_success(self, duration: datetime.timedelta, reply: Mapping[str, Any], command_name: str, request_id: int, connection_id: Tuple[str, int], op_id: Optional[int] = ...) -> None: ... + def publish_command_failure(self, duration: datetime.timedelta, failure: Mapping[str, Any], command_name: str, request_id: int, connection_id: Tuple[str, int], op_id: Optional[int] = ...) -> None: ... + def publish_server_heartbeat_started(self, connection_id: Tuple[str, int]) -> None: ... + def publish_server_heartbeat_succeeded(self, connection_id: Tuple[str, int], duration: int, reply: Union[Mapping[str, Any], Exception]) -> None: ... + def publish_server_heartbeat_failed(self, connection_id: Tuple[str, int], duration: int, reply: Union[Mapping[str, Any], Exception]) -> None: ... + def publish_server_opened(self, server_address: Tuple[str, int], topology_id: int) -> None: ... + def publish_server_closed(self, server_address: Tuple[str, int], topology_id: int) -> None: ... + def publish_server_description_changed(self, previous_description: ServerDescription, new_description: ServerDescription, server_address: Tuple[str, int], topology_id: int) -> None: ... + def publish_topology_opened(self, topology_id: int) -> None: ... + def publish_topology_closed(self, topology_id: int) -> None: ... + def publish_topology_description_changed(self, previous_description: ServerDescription, new_description: ServerDescription, topology_id: int) -> None: ... diff --git a/pymongo/network.pyi b/pymongo/network.pyi new file mode 100644 index 0000000000..18b1d8142b --- /dev/null +++ b/pymongo/network.pyi @@ -0,0 +1,18 @@ +from socket import socket +from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union + +from bson import CodecOptions +from pymongo.collation import Collation +from pymongo.monitoring import _EventListeners +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode + + +def command(sock: socket, dbname: str, spec: Mapping[str, Any], slave_ok: bool, is_mongos: bool, read_preference: _ServerMode, codec_options: CodecOptions, check: bool = ..., allowable_errors: Optional[Sequence[str]] = ..., address: Optional[Tuple[str, int]] = ..., check_keys: bool = ..., listeners: Optional[_EventListeners] = ..., max_bson_size: Optional[int] = ..., read_concern: ReadConcern = ..., parse_write_concern_error: bool = ..., collation: Optional[Collation] = ...) -> Dict[str, Any]: ... +def receive_message(sock: socket, operation: int, request_id: int, max_message_size: int = ...) -> bytes: ... +def _receive_data_on_socket(sock: socket, length: int) -> bytes: ... +def _errno_from_exception(exc: Exception) -> Union[int, str, None]: ... + +class SocketChecker(object): + def __init__(self) -> None: ... + def socket_closed(self, sock: socket) -> bool: ... diff --git a/pymongo/operations.pyi b/pymongo/operations.pyi new file mode 100644 index 0000000000..f42bcc0b91 --- /dev/null +++ b/pymongo/operations.pyi @@ -0,0 +1,44 @@ +from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union + +from pymongo.bulk import _Bulk + + +class _WriteOp(object): + def __init__(self, filter: Optional[Mapping[str, Any]] = None, doc: Optional[Mapping[str, Any]] = None, upsert: Optional[bool] = None) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + +class InsertOne(_WriteOp): + def __init__(self, document: Mapping[str, Any]) -> None: ... + def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... + def __repr__(self) -> str: ... + +class DeleteOne(_WriteOp): + def __init__(self, filter: Mapping[str, Any]) -> None: ... + def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... + def __repr__(self) -> str: ... + +class DeleteMany(_WriteOp): + def __init__(self, filter: Mapping[str, Any]) -> None: ... + def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... + def __repr__(self) -> str: ... + +class ReplaceOne(_WriteOp): + def __init__(self, filter: Mapping[str, Any], replacement: Mapping[str, Any], upsert: bool = False) -> None: ... + def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... + def __repr__(self) -> str: ... + +class UpdateOne(_WriteOp): + def __init__(self, filter: Mapping[str, Any], update: Mapping[str, Any], upsert: bool = False) -> None: ... + def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... + def __repr__(self) -> None: ... + +class UpdateMany(_WriteOp): + def __init__(self, filter: Mapping[str, Any], update: Mapping[str, Any], upsert: bool = False) -> None: ... + def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... + def __repr__(self) -> None: ... + +class IndexModel(object): + def __init__(self, keys: Union[str, Sequence[Tuple[str, Union[int, str]]]], **kwargs: Any) -> None: ... + @property + def document(self) -> Dict[str, Any]: ... diff --git a/pymongo/periodic_executor.pyi b/pymongo/periodic_executor.pyi new file mode 100644 index 0000000000..e715301b28 --- /dev/null +++ b/pymongo/periodic_executor.pyi @@ -0,0 +1,16 @@ +import weakref +from typing import Any, Callable, Optional + + +class PeriodicExecutor(object): + def __init__(self, interval: int, min_interval: int, target: Callable[..., Any], name: Optional[str] = None) -> None: ... + def open(self) -> None: ... + def close(self, dummy: Optional[Any] = None) -> None: ... + def join(self, timeout: int = None) -> None: ... + def wake(self) -> None: ... + def __should_stop(self) -> bool: ... + def _run(self) -> None: ... + +def _register_executor(executor: PeriodicExecutor) -> None: ... +def _on_executor_deleted(ref: weakref.ref) -> None: ... +def _shutdown_executors() -> None: ... diff --git a/pymongo/pool.pyi b/pymongo/pool.pyi new file mode 100644 index 0000000000..f8bd76f3fc --- /dev/null +++ b/pymongo/pool.pyi @@ -0,0 +1,76 @@ +import contextlib +from socket import socket +from ssl import SSLContext +from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union + +from bson.codec_options import CodecOptions +from pymongo.auth import MongoCredential +from pymongo.collation import Collation +from pymongo.ismaster import IsMaster +from pymongo.monitoring import _EventListeners +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.write_concern import WriteConcern + + +def _raise_connection_failure(address: Tuple[str, int], error: Exception) -> None: ... +class PoolOptions(object): + def __init__(self, max_pool_size: int = ..., min_pool_size: int = ..., max_idle_time_ms: Optional[int] = ..., connect_timeout: Optional[int] = ..., socket_timeout: Optional[int] = ..., wait_queue_timeout: Optional[int] = ..., wait_queue_multiple: Optional[int] = ..., ssl_context: Union[SSLContext, None] = ..., ssl_match_hostname: bool = ..., socket_keepalive: bool = ..., event_listeners: Optional[_EventListeners] = ..., appname: Optional[str] = ...) -> None: ... + @property + def max_pool_size(self) -> int: ... + @property + def min_pool_size(self) -> int: ... + @property + def max_idle_time_ms(self) -> int: ... + @property + def connect_timeout(self) -> int: ... + @property + def socket_timeout(self) -> int: ... + @property + def wait_queue_timeout(self) -> int: ... + @property + def wait_queue_multiple(self) -> int: ... + @property + def ssl_context(self) -> SSLContext: ... + @property + def ssl_match_hostname(self) -> bool: ... + @property + def socket_keepalive(self) -> bool: ... + @property + def event_listeners(self) -> _EventListeners: ... + @property + def appname(self) -> str: ... + @property + def metadata(self) -> Dict[str, Any]: ... + +class SocketInfo(object): + def __init__(self, sock: socket, pool: Pool, ismaster: IsMaster, address: Tuple[str, int]) -> None: ... + def command(self, dbname: str, spec: Mapping[str, Any], slave_ok: bool = ..., read_preference: _ServerMode = ..., codec_options: CodecOptions = ..., check: bool = ..., allowable_errors: Optional[Sequence[str]] = ..., check_keys: bool = ..., read_concern: ReadConcern = ..., write_concern: Optional[WriteConcern] = ..., parse_write_concern_error: bool = ..., collation: Optional[Collation] = ...) -> Dict[str, MongoCredential]: ... + def send_message(self, message: bytes, max_doc_size: int) -> None: ... + def receive_message(self, operation: bytes, request_id: int) -> bytes: ... + def legacy_write(self, request_id: int, msg: bytes, max_doc_size: int, with_last_error: bool) -> Dict[str, Any]: ... + def write_command(self, request_id: int, msg: bytes) -> Dict[str, Any]: ... + def check_auth(self, all_credentials: Mapping[str, MongoCredential]) -> None: ... + def authenticate(self, credentials: MongoCredential) -> None: ... + def close(self) -> None: ... + def _raise_connection_failure(self, error: Exception) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __repr__(self) -> str: ... + +def _create_connection(address: Tuple[str, int], options: PoolOptions) -> socket: ... +def _configured_socket(address: Tuple[str, int], options: PoolOptions) -> socket: ... + +class Pool: + def __init__(self, address: Tuple[str, int], options: PoolOptions, handshake: bool = ...) -> None: ... + def reset(self) -> None: ... + def remove_stale_sockets(self) -> None: ... + def connect(self) -> SocketInfo: ... + @contextlib.contextmanager + def get_socket(self, all_credentials: Mapping[str, MongoCredential], checkout: bool = ...) -> SocketInfo: ... + def _get_socket_no_auth(self) -> SocketInfo: ... + def return_socket(self, sock_info: SocketInfo) -> None: ... + def _check(self, sock_info: SocketInfo) -> SocketInfo: ... + def _raise_wait_queue_timeout(self) -> None: ... + def __del__(self) -> None: ... diff --git a/pymongo/read_concern.pyi b/pymongo/read_concern.pyi new file mode 100644 index 0000000000..2ce65e0181 --- /dev/null +++ b/pymongo/read_concern.pyi @@ -0,0 +1,14 @@ +from typing import Any, Dict, Optional + + +class ReadConcern(object): + def __init__(self, level: Optional[str] = None) -> None: ... + @property + def level(self) -> str: ... + @property + def ok_for_legacy(self) -> bool: ... + @property + def document(self) -> Dict[str, str]: ... + def __eq__(self, other: Any) -> bool: ... + def __repr__(self) -> str: ... +DEFAULT_READ_CONCERN: ReadConcern = ... diff --git a/pymongo/read_preferences.pyi b/pymongo/read_preferences.pyi new file mode 100644 index 0000000000..869bef60a7 --- /dev/null +++ b/pymongo/read_preferences.pyi @@ -0,0 +1,75 @@ +from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union + +from pymongo.server_description import ServerDescription +from pymongo.server_selectors import Selection + +_PRIMARY: int = ... +_PRIMARY_PREFERRED: int = ... +_SECONDARY: int = ... +_SECONDARY_PREFERRED: int = ... +_NEAREST: int = ... +_MONGOS_MODES: Tuple[str, ...] = ... +def _validate_tag_sets(tag_sets: Union[Sequence[Mapping[str, Any]], None]) -> Optional[List[Mapping[str, Any]]]: ... +def _invalid_max_staleness_msg(max_staleness: int) -> str: ... +def _validate_max_staleness(max_staleness: int) -> int: ... + +class _ServerMode(object): + def __init__(self, mode: int, tag_sets: Optional[Sequence[Mapping[str, Any]]] = None, max_staleness: int = -1) -> None: ... + @property + def name(self) -> str: ... + @property + def document(self) -> Dict[str, Union[str, List[Dict[str, Any]], int]]: ... + @property + def mode(self) -> int: ... + @property + def tag_sets(self) -> List[Dict[Any, Any]]: ... + @property + def max_staleness(self) -> int: ... + @property + def min_wire_version(self) -> int: ... + def __repr__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __getstate__(self) -> Dict[str, Union[int, List[Dict[Any, Any]]]]: ... + def __setstate__(self, value: Mapping[str, Union[int, Sequence[Mapping[Any, Any]]]]) -> None: ... + +class Primary(_ServerMode): + def __init__(self) -> None: ... + def __call__(self, selection: Selection) -> List[ServerDescription]: ... + def __repr__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + +class PrimaryPreferred(_ServerMode): + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = None, max_staleness: int = -1) -> None: ... + def __call__(self, selection: Selection) -> Union[List[ServerDescription], Selection]: ... + +class Secondary(_ServerMode): + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = None, + max_staleness: int = -1) -> None: ... + def __call__(self, selection: Selection) -> Selection: ... + +class SecondaryPreferred(_ServerMode): + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = None, max_staleness: int = -1) -> None: ... + def __call__(self, selection: Selection) -> Union[List[ServerDescription], Selection]: ... + +class Nearest(_ServerMode): + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = None, max_staleness: int = -1) -> None: ... + def __call__(self, selection: Selection) -> Selection: ... + +def make_read_preference(mode: int, tag_sets: Sequence[Mapping[str, Any]], max_staleness: int = -1) -> _ServerMode: ... +_MODES: Tuple[str, ...] = ... + +class ReadPreference(object): + PRIMARY: _ServerMode = ... + PRIMARY_PREFERRED: _ServerMode = ... + SECONDARY: _ServerMode = ... + SECONDARY_PREFERRED: _ServerMode = ... + NEAREST: _ServerMode = ... + +def read_pref_mode_from_name(name: str) -> int: ... + +class MovingAverage(object): + def __init__(self) -> None: ... + def add_sample(self, sample: int) -> None: ... + def get(self) -> Optional[float]: ... + def reset(self) -> None: ... diff --git a/pymongo/response.pyi b/pymongo/response.pyi new file mode 100644 index 0000000000..6318b3232d --- /dev/null +++ b/pymongo/response.pyi @@ -0,0 +1,25 @@ +import datetime + +from typing import Tuple + +from pymongo.pool import Pool, SocketInfo + +class Response(object): + def __init__(self, data: bytes, address: Tuple[str, int], request_id: int, duration: datetime.timedelta, from_command: bool) -> None: ... + @property + def data(self) -> bytes: ... + @property + def address(self) -> Tuple[str, int]: ... + @property + def request_id(self) -> int: ... + @property + def duration(self) -> datetime.timedelta: ... + @property + def from_command(self) -> bool: ... + +class ExhaustResponse(Response): + def __init__(self, data: bytes, address: Tuple[str, int], socket_info: SocketInfo, pool: Pool, request_id: int, duration: datetime.timedelta, from_command: bool) -> None: ... + @property + def socket_info(self) -> SocketInfo: ... + @property + def pool(self) -> Pool: ... diff --git a/pymongo/results.pyi b/pymongo/results.pyi new file mode 100644 index 0000000000..504e0efbc2 --- /dev/null +++ b/pymongo/results.pyi @@ -0,0 +1,54 @@ +from typing import Any, Dict, List, Mapping, Sequence + + +class _WriteResult(object): + def __init__(self, acknowledged: bool) -> None: ... + def _raise_if_unacknowledged(self, property_name: str) -> None: ... + @property + def acknowledged(self) -> bool: ... + +class InsertOneResult(_WriteResult): + def __init__(self, inserted_id: Sequence[Any], acknowledged: bool) -> None: ... + @property + def inserted_id(self) -> List[Any]: ... + +class InsertManyResult(_WriteResult): + def __init__(self, inserted_ids: Any, acknowledged: bool) -> None: ... + @property + def inserted_ids(self) -> Any: ... + +class UpdateResult(_WriteResult): + def __init__(self, raw_result: Mapping[str, Any], acknowledged: bool) -> None: ... + @property + def raw_result(self) -> Dict[str, Any]: ... + @property + def matched_count(self) -> int: ... + @property + def modified_count(self) -> int: ... + @property + def upserted_id(self) -> Any: ... + +class DeleteResult(_WriteResult): + def __init__(self, raw_result: Mapping[str, Any], acknowledged: bool) -> None: ... + @property + def raw_result(self) -> Dict[str, Any]: ... + @property + def deleted_count(self) -> int: ... + +class BulkWriteResult(_WriteResult): + def __init__(self, bulk_api_result: Mapping[str, Any], acknowledged: bool)\ + -> None: ... + @property + def bulk_api_result(self) -> Dict[str, Any]: ... + @property + def inserted_count(self) -> int: ... + @property + def matched_count(self) -> int: ... + @property + def modified_count(self) -> int: ... + @property + def deleted_count(self) -> int: ... + @property + def upserted_count(self) -> int: ... + @property + def upserted_ids(self) -> Dict[Any, Any]: ... diff --git a/pymongo/server.pyi b/pymongo/server.pyi new file mode 100644 index 0000000000..09eab3d796 --- /dev/null +++ b/pymongo/server.pyi @@ -0,0 +1,33 @@ +import contextlib + +from queue import Queue +from typing import Iterator, Mapping, Optional, Tuple, Union + +from bson import ObjectId +from pymongo.auth import MongoCredential +from pymongo.message import _GetMore, _Query +from pymongo.monitor import Monitor +from pymongo.monitoring import _EventListeners +from pymongo.pool import Pool, SocketInfo +from pymongo.response import Response +from pymongo.server_description import ServerDescription + + +class Server(object): + def __init__(self, server_description: ServerDescription, pool: Pool, monitor: Monitor, topology_id: Optional[ObjectId] = None, listeners: Optional[_EventListeners] = None, events: Optional[Queue] = None) -> None: ... + def open(self) -> None: ... + def reset(self) -> None: ... + def close(self) -> None: ... + def request_check(self) -> None: ... + def send_message(self, message: Tuple[int, bytes], all_credentials: Mapping[str, MongoCredential]) -> None: ... + def send_message_with_response(self, operation: Union[_Query, _GetMore], set_slave_okay: bool, all_credentials: Mapping[str, MongoCredential], listeners: _EventListeners, exhaust: bool = False) -> Response: ... + @contextlib.contextmanager + def get_socket(self, all_credentials: Mapping[str, MongoCredential], checkout: bool = False) -> Iterator[SocketInfo]: ... + @property + def description(self) -> ServerDescription: ... + @description.setter + def description(self, server_description: ServerDescription) -> None: ... + @property + def pool(self) -> Pool: ... + def _split_message(self, message: Union[Tuple[int, bytes, int], Tuple[int, bytes]]) -> Tuple[int, bytes, int]: ... + def __str__(self) -> str: ... diff --git a/pymongo/server_description.pyi b/pymongo/server_description.pyi new file mode 100644 index 0000000000..27c38d622d --- /dev/null +++ b/pymongo/server_description.pyi @@ -0,0 +1,56 @@ +import datetime +from typing import Any, Dict, Optional, Set, Tuple + +from pymongo.ismaster import IsMaster + + +def _total_seconds(delta: datetime.timedelta) -> float: ... + +class ServerDescription(object): + def __init__(self, address: Tuple[str, int], ismaster: Optional[IsMaster] = ..., round_trip_time: Optional[float] = ..., error: Optional[Any] = ...) -> None: ... + @property + def address(self) -> Tuple[str, int]: ... + @property + def server_type(self) -> int: ... + @property + def server_type_name(self) -> str: ... + @property + def all_hosts(self) -> Set[Tuple[str, int]]: ... + @property + def tags(self) -> Dict[Any, Any]: ... + @property + def replica_set_name(self) -> Optional[str]: ... + @property + def primary(self) -> Optional[Tuple[str, int]]: ... + @property + def max_bson_size(self) -> int: ... + @property + def max_message_size(self) -> int: ... + @property + def max_write_batch_size(self) -> int: ... + @property + def min_wire_version(self) -> int: ... + @property + def max_wire_version(self) -> int: ... + @property + def set_version(self) -> int: ... + @property + def election_id(self) -> int: ... + @property + def election_tuple(self) -> Tuple[int, int]: ... + @property + def me(self) -> Tuple[str, int]: ... + @property + def last_write_date(self) -> Dict[Any, Any]: ... + @property + def last_update_time(self) -> float: ... + @property + def round_trip_time(self) -> float: ... + @property + def error(self) -> Any: ... + @property + def is_writable(self) -> bool: ... + @property + def is_readable(self) -> bool: ... + @property + def is_server_type_known(self) -> bool: ... diff --git a/pymongo/server_selectors.pyi b/pymongo/server_selectors.pyi new file mode 100644 index 0000000000..6e7eff48fd --- /dev/null +++ b/pymongo/server_selectors.pyi @@ -0,0 +1,31 @@ +from typing import Any, Mapping, Sequence + +from pymongo.server_description import ServerDescription +from pymongo.topology_description import TopologyDescription + + +class Selection(object): + @classmethod + def from_topology_description(cls: type, topology_description: TopologyDescription) -> 'Selection': ... + def __init__(self, topology_description: TopologyDescription, server_descriptions: Sequence[ServerDescription], common_wire_version: int, primary: ServerDescription) -> None: ... + def with_server_descriptions(self, server_descriptions: Sequence[ServerDescription]) -> 'Selection': ... + def secondary_with_max_last_write_date(self) -> ServerDescription: ... + @property + def primary_selection(self) -> 'Selection': ... + @property + def heartbeat_frequency(self) -> int: ... + @property + def topology_type(self) -> int: ... + def __bool__(self) -> bool: ... + def __getitem__(self, item: int) -> ServerDescription: ... + +def any_server_selector(selection: Selection) -> Selection: ... +def readable_server_selector(selection: Selection) -> Selection: ... +def writable_server_selector(selection: Selection) -> Selection: ... +def secondary_server_selector(selection: Selection) -> Selection: ... +def arbiter_server_selector(selection: Selection) -> Selection: ... +def writable_preferred_server_selector(selection: Selection) -> Selection: ... +def apply_single_tag_set(tag_set: Mapping[str, Any], selection: Selection) -> Selection: ... +def apply_tag_sets(tag_sets: Sequence[Mapping[str, Any]], selection: Selection) -> Selection: ... +def secondary_with_tags_server_selector(tag_sets: Sequence[Mapping[str, Any]], selection: Selection) -> Selection: ... +def member_with_tags_server_selector(tag_sets: Sequence[Mapping[str, Any]], selection: Selection) -> Selection: ... diff --git a/pymongo/server_type.pyi b/pymongo/server_type.pyi new file mode 100644 index 0000000000..4788aa66c2 --- /dev/null +++ b/pymongo/server_type.pyi @@ -0,0 +1,13 @@ +from typing import NamedTuple + +class ServerType(NamedTuple): + Unknown: int + Mongos: int + RSPrimary: int + RSSecondary: int + RSArbiter: int + RSOther: int + RSGhost: int + Standalone: int + +SERVER_TYPE: ServerType = ... diff --git a/pymongo/settings.pyi b/pymongo/settings.pyi new file mode 100644 index 0000000000..757e96b15d --- /dev/null +++ b/pymongo/settings.pyi @@ -0,0 +1,32 @@ +import threading +from typing import Dict, List, Optional, Sequence, Tuple + +from pymongo.monitor import Monitor +from pymongo.pool import Pool, PoolOptions +from pymongo.server_description import ServerDescription + + +class TopologySettings(object): + def __init__(self, seeds: Optional[Sequence[Tuple[str, int]]] = ..., replica_set_name: Optional[str] = ..., pool_class: Optional[Pool] = ..., pool_options: Optional[PoolOptions] = ..., monitor_class: Optional[Monitor] = ..., condition_class: Optional[threading.Condition] = ..., local_threshold_ms: int = ..., server_selection_timeout: int = ..., heartbeat_frequency: int = ...) -> None: ... + @property + def seeds(self) -> List[Tuple[str, int]]: ... + @property + def replica_set_name(self) -> str: ... + @property + def pool_class(self) -> Pool: ... + @property + def pool_options(self) -> PoolOptions: ... + @property + def monitor_class(self) -> Monitor: ... + @property + def condition_class(self) -> threading.Condition: ... + @property + def local_threshold_ms(self) -> int: ... + @property + def server_selection_timeout(self) -> int: ... + @property + def heartbeat_frequency(self) -> int: ... + @property + def direct(self) -> bool: ... + def get_topology_type(self) -> int: ... + def get_server_descriptions(self) -> Dict[Tuple[str, int], ServerDescription]: ... diff --git a/pymongo/son_manipulator.pyi b/pymongo/son_manipulator.pyi new file mode 100644 index 0000000000..55ef98bcba --- /dev/null +++ b/pymongo/son_manipulator.pyi @@ -0,0 +1,26 @@ +from typing import Any, Dict, Mapping + +from pymongo.collection import Collection +from pymongo.database import Database + + +class SONManipulator(object): + def will_copy(self) -> bool: ... + def transform_incoming(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + def transform_outgoing(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + +class ObjectIdInjector(SONManipulator): + def transform_incoming(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + +class ObjectIdShuffler(SONManipulator): + def will_copy(self) -> bool: ... + def transform_incoming(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + +class NamespaceInjector(SONManipulator): + def transform_incoming(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + +class AutoReference(SONManipulator): + def __init__(self, db: Database) -> None: ... + def will_copy(self) -> bool: ... + def transform_incoming(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + def transform_outgoing(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... diff --git a/pymongo/ssl_context.pyi b/pymongo/ssl_context.pyi new file mode 100644 index 0000000000..bafd0eff8e --- /dev/null +++ b/pymongo/ssl_context.pyi @@ -0,0 +1,18 @@ +from socket import socket +from typing import Any, Optional + +try: + import ssl +except ImportError: + pass + + +class SSLContext(object): + def __init__(self, protocol: int) -> None: ... + @property + def protocol(self) -> int: ... + def __get_verify_mode(self) -> int: ... + def __set_verify_mode(self, value: int) -> None: ... + def load_cert_chain(self, certfile: str, keyfile: Optional[str] = ...) -> None: ... + def load_verify_locations(self, cafile: Optional[str] = ..., dummy: Optional[Any] = ...) -> None: ... + def wrap_socket(self, sock: socket, server_side: bool = ..., do_handshake_on_connect: bool = ..., suppress_ragged_eofs: bool = ..., dummy: Optional[Any] = ...) -> ssl.SSLSocket: ... diff --git a/pymongo/ssl_match_hostname.pyi b/pymongo/ssl_match_hostname.pyi new file mode 100644 index 0000000000..6b99fa2ffc --- /dev/null +++ b/pymongo/ssl_match_hostname.pyi @@ -0,0 +1,6 @@ +from typing import Any, Mapping, Match, Union + +class CertificateError(ValueError): ... +def _dnsname_match(dn, hostname: str, max_wildcards: int = 1) -> Union[bool, None, Match[str]]: ... +def _ipaddress_match(ipname: str, host_ip: str) -> bool: ... +def match_hostname(cert: Mapping[str, Any], hostname: str) -> None: ... diff --git a/pymongo/ssl_support.pyi b/pymongo/ssl_support.pyi new file mode 100644 index 0000000000..aaa5b64859 --- /dev/null +++ b/pymongo/ssl_support.pyi @@ -0,0 +1,5 @@ +from typing import Any, Union + +def validate_cert_reqs(option: str, value: Union[str, int]) -> Any: ... +def _load_wincerts() -> None: ... +def get_ssl_context(*args: Any) -> Any: ... diff --git a/pymongo/thread_util.pyi b/pymongo/thread_util.pyi new file mode 100644 index 0000000000..0cead115e9 --- /dev/null +++ b/pymongo/thread_util.pyi @@ -0,0 +1,29 @@ +from typing import Any, Optional, Union + + +class Semaphore: + def __init__(self, value: int = ...) -> None: ... + def acquire(self, blocking: bool = ..., timeout: Optional[int] = ...) -> bool: ... + def release(self) -> None: ... + def __exit__(self, t: Any, v: Any, tb: Any) -> None: ... + @property + def counter(self) -> int: ... + +class BoundedSemaphore(Semaphore): + def __init__(self, value: int = ...) -> None: ... + def release(self) -> None: ... + +class DummySemaphore(object): + def __init__(self, value: Optional[int] = ...) -> None: ... + def acquire(self, blocking: bool = ..., timeout: Optional[int] = ...) -> bool: ... + def release(self) -> None: ... + +class MaxWaitersBoundedSemaphore(object): + def __init__(self, semaphore_class: Semaphore, value: int = ..., max_waiters: int = ...) -> None: ... + def acquire(self, blocking: bool = ..., timeout: Optional[int] = ...) -> bool: ... + def __getattr__(self, name: str) -> Any: ... + +class MaxWaitersBoundedSemaphoreThread(MaxWaitersBoundedSemaphore): + def __init__(self, value: int = ..., max_waiters: int = ...) -> None: ... + +def create_semaphore(max_size: int, max_waiters: int) -> Union[Semaphore, MaxWaitersBoundedSemaphore]: ... diff --git a/pymongo/topology.pyi b/pymongo/topology.pyi new file mode 100644 index 0000000000..c7eb41a5b6 --- /dev/null +++ b/pymongo/topology.pyi @@ -0,0 +1,42 @@ +from typing import Callable, List, Optional, Sequence, Set, Tuple, Union +from queue import Queue + +from pymongo.pool import Pool +from pymongo.server import Server +from pymongo.server_description import ServerDescription +from pymongo.server_selectors import Selection +from pymongo.settings import TopologySettings + + +def process_events_queue(queue_ref: Queue) -> bool: ... + +class Topology(object): + def __init__(self, topology_settings: TopologySettings) -> None: ... + def open(self) -> None: ... + def select_servers(self, selector: Callable[[Sequence[Server]], Sequence[Server]], server_selection_timeout: Optional[int] = ..., address: Optional[Tuple[str, int]] = ...) -> List[Server]: ... + def select_server(self, selector: Callable[[Sequence[Server]], Sequence[Server]], server_selection_timeout: Optional[int] = ..., address: Optional[Tuple[str, int]] = ...) -> Server: ... + def select_server_by_address(self, address: Tuple[str, int], server_selection_timeout: Optional[int] = ...) -> Server: ... + def on_change(self, server_description: ServerDescription) -> None: ... + def get_server_by_address(self, address: Tuple[str, int]) -> Optional[Server]: ... + def has_server(self, address: Tuple[str, int]) -> bool: ... + def get_primary(self) -> Optional[Tuple[str, int]]: ... + def _get_replica_set_members(self, selector: Callable[[Selection], Sequence[ServerDescription]]) -> Set[Tuple[str, int]]: ... + def get_secondaries(self) -> Set[Tuple[str, int]]: ... + def get_arbiters(self) -> Set[Tuple[str, int]]: ... + def request_check_all(self, wait_time: int = ...) -> None: ... + def reset_pool(self, address: Tuple[str, int]) -> None: ... + def reset_server(self, address: Tuple[str, int]) -> None: ... + def reset_server_and_request_check(self, address: Tuple[str, int]) -> None: ... + def update_pool(self) -> None: ... + def close(self) -> None: ... + @property + def description(self) -> ServerDescription: ... + def _new_selection(self) -> Selection: ... + def _ensure_opened(self) -> None: ... + def _reset_server(self, address: Tuple[str, int]) -> None: ... + def _request_check(self, address: Tuple[str, int]) -> None: ... + def _request_check_all(self) -> None: ... + def _update_servers(self) -> None: ... + def _create_pool_for_server(self, address: Tuple[str, int]) -> Pool: ... + def _create_pool_for_monitor(self, address: Tuple[str, int]) -> Pool: ... + def _error_message(self, selector: Callable[[Selection], Selection]) -> str: ... diff --git a/pymongo/topology_description.pyi b/pymongo/topology_description.pyi new file mode 100644 index 0000000000..cd9cc65af6 --- /dev/null +++ b/pymongo/topology_description.pyi @@ -0,0 +1,50 @@ +from typing import Callable, Dict, List, Mapping, NamedTuple, Optional, Tuple, Union + +from pymongo.read_preferences import _ServerMode +from pymongo.server import Server +from pymongo.server_description import ServerDescription +from pymongo.server_selectors import Selection +from pymongo.settings import TopologySettings + + +class TopologyType(NamedTuple): + Single: int + ReplicaSetNoPrimary: int + ReplicaSetWithPrimary: int + Sharded: int + Unknown: int +TOPOLOGY_TYPE: TopologyType = ... + +class TopologyDescription(object): + def __init__(self, topology_type: int, server_descriptions: Mapping[Tuple[str, int], ServerDescription], replica_set_name: Optional[str], max_set_version: Optional[int], max_election_id: Optional[int], topology_settings: TopologySettings) -> None: ... + def check_compatible(self) -> None: ... + def has_server(self, address: Tuple[str, int]) -> bool: ... + def reset_server(self, address: Tuple[str, int]) -> 'TopologyDescription': ... + def reset(self) -> 'TopologyDescription': ... + def server_descriptions(self) -> Dict[Tuple[str, int], ServerDescription]: ... + @property + def topology_type(self) -> int: ... + @property + def topology_type_name(self) -> str: ... + @property + def replica_set_name(self) -> str: ... + @property + def max_set_version(self) -> int: ... + @property + def max_election_id(self) -> int: ... + @property + def known_servers(self) -> List[Server]: ... + @property + def common_wire_version(self) -> Optional[int]: ... + @property + def heartbeat_frequency(self) -> int: ... + def apply_selector(self, selector: Union[Selection, Callable[[Selection], Selection], _ServerMode], address: Tuple[str, int]) -> List[ServerDescription]: ... + def has_readable_server(self, read_preference: _ServerMode = ...) -> bool: ... + def has_writable_server(self) -> bool: ... + +_SERVER_TYPE_TO_TOPOLOGY_TYPE: Dict[int, int] = ... +def updated_topology_description(topology_description: TopologyDescription, server_description: ServerDescription) -> TopologyDescription: ... +def _update_rs_from_primary(sds: Mapping[Tuple[str, int], ServerDescription], replica_set_name: str, server_description: ServerDescription, max_set_version: int, max_election_id: int) -> Tuple[int, str, int, int]: ... +def _update_rs_with_primary_from_member(sds: Mapping[Tuple[str, int], ServerDescription], replica_set_name: str, server_description: ServerDescription) -> int: ... +def _update_rs_no_primary_from_member(sds: Mapping[Tuple[str, int], ServerDescription], replica_set_name: str, server_description: ServerDescription) -> Tuple[int, str]: ... +def _check_has_primary(sds: Mapping[Tuple[str, int], ServerDescription]) -> int: ... diff --git a/pymongo/write_concern.pyi b/pymongo/write_concern.pyi new file mode 100644 index 0000000000..7d67fab5b5 --- /dev/null +++ b/pymongo/write_concern.pyi @@ -0,0 +1,12 @@ +from typing import Any, Dict, Optional, Union + +class WriteConcern(object): + def __init__(self, w: Optional[Union[int, str]] = ..., wtimeout: Optional[int] = ..., j: Optional[bool] = ..., fsync: Optional[bool] = ...) -> None: ... + @property + def document(self) -> Dict[str, Any]: ... + @property + def acknowledged(self) -> bool: ... + def __repr__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __bool__(self) -> bool: ... From 3583b1ebcb97d752b1c8404963d7db593eab70d6 Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Wed, 6 Mar 2019 15:39:54 +0100 Subject: [PATCH 2/2] Add stub files for bson and fix the ones for pymongo. --- bson/__init__.pyi | 61 +++++++ bson/binary.pyi | 36 ++++ bson/code.pyi | 12 ++ bson/codec_options.pyi | 26 +++ bson/dbref.pyi | 27 +++ bson/decimal128.pyi | 18 ++ bson/errors.pyi | 9 + bson/int64.pyi | 7 + bson/json_util.pyi | 42 +++++ bson/max_key.pyi | 14 ++ bson/min_key.pyi | 14 ++ bson/objectid.pyi | 26 +++ bson/py.typed | 0 bson/raw_bson.pyi | 16 ++ bson/regex.pyi | 17 ++ bson/son.pyi | 25 +++ bson/timestamp.pyi | 23 +++ bson/tz_util.pyi | 17 ++ pymongo/__init__.pyi | 37 ++-- pymongo/auth.pyi | 34 ++-- pymongo/bulk.pyi | 30 +++- pymongo/change_stream.pyi | 31 ++++ pymongo/client_options.pyi | 9 - pymongo/client_session.pyi | 74 ++++++++ pymongo/collation.pyi | 13 +- pymongo/collection.pyi | 253 ++++++++++++++++++++++------ pymongo/command_cursor.pyi | 15 +- pymongo/common.pyi | 15 +- pymongo/compression_support.pyi | 27 +++ pymongo/cursor.pyi | 46 +++-- pymongo/database.pyi | 111 ++++++++---- pymongo/driver_info.pyi | 4 + pymongo/errors.pyi | 16 +- pymongo/helpers.pyi | 21 --- pymongo/ismaster.pyi | 1 - pymongo/max_staleness_selectors.pyi | 3 - pymongo/message.pyi | 107 ++++++++---- pymongo/mongo_client.pyi | 37 ++-- pymongo/monitor.pyi | 13 +- pymongo/monitoring.pyi | 88 +++++++--- pymongo/monotonic.pyi | 1 + pymongo/network.pyi | 20 ++- pymongo/operations.pyi | 49 ++++-- pymongo/periodic_executor.pyi | 12 +- pymongo/pool.pyi | 50 ++++-- pymongo/py.typed | 0 pymongo/read_concern.pyi | 2 +- pymongo/read_preferences.pyi | 17 +- pymongo/response.pyi | 18 +- pymongo/results.pyi | 1 - pymongo/saslprep.pyi | 3 + pymongo/server.pyi | 29 +++- pymongo/server_description.pyi | 10 +- pymongo/server_selectors.pyi | 7 +- pymongo/server_type.pyi | 19 ++- pymongo/settings.pyi | 12 +- pymongo/ssl_context.pyi | 8 +- pymongo/ssl_match_hostname.pyi | 2 - pymongo/ssl_support.pyi | 8 +- pymongo/topology.pyi | 35 ++-- pymongo/topology_description.pyi | 37 ++-- pymongo/uri_parser.pyi | 20 +++ pymongo/write_concern.pyi | 9 +- setup.py | 4 + 64 files changed, 1362 insertions(+), 386 deletions(-) create mode 100644 bson/__init__.pyi create mode 100644 bson/binary.pyi create mode 100644 bson/code.pyi create mode 100644 bson/codec_options.pyi create mode 100644 bson/dbref.pyi create mode 100644 bson/decimal128.pyi create mode 100644 bson/errors.pyi create mode 100644 bson/int64.pyi create mode 100644 bson/json_util.pyi create mode 100644 bson/max_key.pyi create mode 100644 bson/min_key.pyi create mode 100644 bson/objectid.pyi create mode 100644 bson/py.typed create mode 100644 bson/raw_bson.pyi create mode 100644 bson/regex.pyi create mode 100644 bson/son.pyi create mode 100644 bson/timestamp.pyi create mode 100644 bson/tz_util.pyi create mode 100644 pymongo/change_stream.pyi create mode 100644 pymongo/client_session.pyi create mode 100644 pymongo/compression_support.pyi create mode 100644 pymongo/driver_info.pyi delete mode 100644 pymongo/helpers.pyi create mode 100644 pymongo/monotonic.pyi create mode 100644 pymongo/py.typed create mode 100644 pymongo/saslprep.pyi create mode 100644 pymongo/uri_parser.pyi diff --git a/bson/__init__.pyi b/bson/__init__.pyi new file mode 100644 index 0000000000..3c9629c1a4 --- /dev/null +++ b/bson/__init__.pyi @@ -0,0 +1,61 @@ +# Stubs for bson (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +import datetime +from typing import Any, BinaryIO, Iterator, List, Mapping, MutableMapping, Sequence + +from bson.binary import Binary as Binary +from bson.code import Code as Code +from bson.codec_options import CodecOptions as CodecOptions +from bson.dbref import DBRef as DBRef +from bson.decimal128 import Decimal128 as Decimal128 +from bson.errors import (InvalidBSON as InvalidBSON, + InvalidDocument as InvalidDocument, + InvalidStringData as InvalidStringData) +from bson.int64 import Int64 as Int64 +from bson.max_key import MaxKey as MaxKey +from bson.min_key import MinKey as MinKey +from bson.objectid import ObjectId as ObjectId +from bson.regex import Regex as Regex +from bson.son import SON as SON +from bson.timestamp import Timestamp as Timestamp +from bson.tz_util import utc as utc + +EPOCH_AWARE: datetime.datetime +EPOCH_NAIVE: datetime.datetime +BSONNUM: bytes +BSONSTR: bytes +BSONOBJ: bytes +BSONARR: bytes +BSONBIN: bytes +BSONUND: bytes +BSONOID: bytes +BSONBOO: bytes +BSONDAT: bytes +BSONNUL: bytes +BSONRGX: bytes +BSONREF: bytes +BSONCOD: bytes +BSONSYM: bytes +BSONCWS: bytes +BSONINT: bytes +BSONTIM: bytes +BSONLON: bytes +BSONDEC: bytes +BSONMIN: bytes +BSONMAX: bytes + +def gen_list_name() -> Iterator[bytes]: ... +def decode_all(data: Sequence[bytes], codec_options: CodecOptions = ...) -> List[Mapping[Any, Any]]: ... + +def decode_iter(data: Sequence[bytes], codec_options: CodecOptions = ...) -> Iterator[MutableMapping[Any, Any]]: ... +def decode_file_iter(file_obj: BinaryIO, codec_options: CodecOptions = ...) -> Iterator[MutableMapping[Any, Any]]: ... +def is_valid(bson: bytes) -> bool: ... + +class BSON(bytes): + @classmethod + def encode(cls, document: Mapping[Any, Any], check_keys: bool = ..., codec_options: CodecOptions = ...) -> BSON: ... # type: ignore + def decode(self, codec_options: CodecOptions = ...) -> MutableMapping[Any, Any]: ... # type: ignore + +def has_c() -> bool: ... diff --git a/bson/binary.pyi b/bson/binary.pyi new file mode 100644 index 0000000000..a4dd8d2f06 --- /dev/null +++ b/bson/binary.pyi @@ -0,0 +1,36 @@ +# Stubs for bson.binary (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Dict, Iterable, Tuple +from uuid import UUID + +BINARY_SUBTYPE: int = ... +FUNCTION_SUBTYPE: int = ... +OLD_BINARY_SUBTYPE: int = ... +OLD_UUID_SUBTYPE: int = ... +UUID_SUBTYPE: int = ... +STANDARD: int = ... +PYTHON_LEGACY: int = ... +JAVA_LEGACY: int = ... +CSHARP_LEGACY: int = ... +ALL_UUID_SUBTYPES: Iterable[int] = ... +ALL_UUID_REPRESENTATIONS: Iterable[int] = ... +UUID_REPRESENTATION_NAMES: Dict[int, str] = ... +MD5_SUBTYPE: int = ... +USER_DEFINED_SUBTYPE: int = ... + +class Binary(bytes): + def __new__(cls, data: bytes, subtype: int = ...) -> Binary: ... + @property + def subtype(self) -> int: ... + def __getnewargs__(self) -> Tuple[bytes, int]: ... # type: ignore + def __eq__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __ne__(self, other: Any) -> bool: ... + +class UUIDLegacy(Binary): + def __new__(cls, obj: UUID) -> UUIDLegacy: ... + def __getnewargs__(self) -> Tuple[UUID]: ... # type: ignore + @property + def uuid(self) -> UUID: ... diff --git a/bson/code.pyi b/bson/code.pyi new file mode 100644 index 0000000000..2eb831698e --- /dev/null +++ b/bson/code.pyi @@ -0,0 +1,12 @@ +# Stubs for bson.code (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Mapping, Optional, Union + +class Code(str): + def __new__(cls, code: Union[Code, str], scope: Optional[Mapping[str, Any]] = ..., **kwargs: Any) -> Code: ... + @property + def scope(self) -> Optional[Mapping[str, Any]]: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... diff --git a/bson/codec_options.pyi b/bson/codec_options.pyi new file mode 100644 index 0000000000..df5dd45c95 --- /dev/null +++ b/bson/codec_options.pyi @@ -0,0 +1,26 @@ +# Stubs for bson.codec_options (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +import datetime +from typing import Any, NamedTuple, Optional + +_options_base = NamedTuple('_options_base', [ + ('document_class', type), + ('tz_aware', bool), + ('uuid_representation', int), + ('unicode_decode_error_handler', str), + ('tzinfo', datetime.tzinfo), +]) + +class CodecOptions(_options_base): + def __new__( + cls, + document_class: type = ..., + tz_aware: bool = ..., + uuid_representation: int = ..., + unicode_decode_error_handler: str = ..., + tzinfo: Optional[datetime.tzinfo] = ...) -> CodecOptions: ... + def with_options(self, **kwargs: Any) -> CodecOptions: ... + +DEFAULT_CODEC_OPTIONS: CodecOptions = ... diff --git a/bson/dbref.pyi b/bson/dbref.pyi new file mode 100644 index 0000000000..8bee375f09 --- /dev/null +++ b/bson/dbref.pyi @@ -0,0 +1,27 @@ +# Stubs for bson.dbref (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Mapping, Optional + +from bson.son import SON + +class DBRef: + def __init__( + self, + collection: str, + id: Any, database: Optional[str] = ..., + _extra: Mapping[str, Any] = ..., + **kwargs: Any) -> None: ... + @property + def collection(self) -> str: ... + @property + def id(self) -> Any: ... + @property + def database(self) -> Optional[str]: ... + def __getattr__(self, key: str) -> Any: ... + def as_doc(self) -> SON[str, Any]: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __deepcopy__(self, memo: Any) -> DBRef: ... diff --git a/bson/decimal128.pyi b/bson/decimal128.pyi new file mode 100644 index 0000000000..74aca6b082 --- /dev/null +++ b/bson/decimal128.pyi @@ -0,0 +1,18 @@ +# Stubs for bson.decimal128 (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +import decimal +from typing import Any, Union + +def create_decimal128_context() -> decimal.Context: ... + +class Decimal128: + def __init__(self, value: Union[str, decimal.Decimal]) -> None: ... + def to_decimal(self) -> decimal.Decimal: ... + @classmethod + def from_bid(cls, value: bytes) -> Decimal128: ... + @property + def bid(self) -> bytes: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... diff --git a/bson/errors.pyi b/bson/errors.pyi new file mode 100644 index 0000000000..e2e21195ad --- /dev/null +++ b/bson/errors.pyi @@ -0,0 +1,9 @@ +# Stubs for bson.errors (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +class BSONError(Exception): ... +class InvalidBSON(BSONError): ... +class InvalidStringData(BSONError): ... +class InvalidDocument(BSONError): ... +class InvalidId(BSONError): ... diff --git a/bson/int64.pyi b/bson/int64.pyi new file mode 100644 index 0000000000..bf8765dd90 --- /dev/null +++ b/bson/int64.pyi @@ -0,0 +1,7 @@ +# Stubs for bson.int64 (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +long = int + +class Int64(long): ... diff --git a/bson/json_util.pyi b/bson/json_util.pyi new file mode 100644 index 0000000000..40c891e6e7 --- /dev/null +++ b/bson/json_util.pyi @@ -0,0 +1,42 @@ +# Stubs for bson.json_util (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from bson.codec_options import CodecOptions +from typing import Any + +class DatetimeRepresentation: + LEGACY: int = ... + NUMBERLONG: int = ... + ISO8601: int = ... + +class JSONMode: + LEGACY: int = ... + RELAXED: int = ... + CANONICAL: int = ... + +class JSONOptions(CodecOptions): + json_mode: int = ... + strict_number_long: bool = ... + datetime_representation: int = ... + strict_uuid: bool = ... + def __new__( + cls, + strict_number_long: bool = ..., + datetime_representation: int = ..., + strict_uuid: bool = ..., + json_mode: int = ..., + *args: Any, + **kwargs: Any) -> JSONOptions: ... + +LEGACY_JSON_OPTIONS: JSONOptions = ... +DEFAULT_JSON_OPTIONS: JSONOptions = ... +CANONICAL_JSON_OPTIONS: JSONOptions = ... +RELAXED_JSON_OPTIONS: JSONOptions = ... +STRICT_JSON_OPTIONS: JSONOptions = ... + +def dumps(obj: Any, *args: Any, **kwargs: Any) -> str: ... +def loads(s: str, *args: Any, **kwargs: Any) -> Any: ... +def object_pairs_hook(pairs: Any, json_options: JSONOptions = ...) -> Any: ... +def object_hook(dct: Any, json_options: JSONOptions = ...) -> Any: ... +def default(obj: Any, json_options: JSONOptions = ...) -> Any: ... diff --git a/bson/max_key.pyi b/bson/max_key.pyi new file mode 100644 index 0000000000..ee1bbfb326 --- /dev/null +++ b/bson/max_key.pyi @@ -0,0 +1,14 @@ +# Stubs for bson.max_key (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any + +class MaxKey: + def __eq__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __ne__(self, other: Any) -> bool: ... + def __le__(self, other: Any) -> bool: ... + def __lt__(self, dummy: Any) -> bool: ... + def __ge__(self, dummy: Any) -> bool: ... + def __gt__(self, other: Any) -> bool: ... diff --git a/bson/min_key.pyi b/bson/min_key.pyi new file mode 100644 index 0000000000..76c0b03eca --- /dev/null +++ b/bson/min_key.pyi @@ -0,0 +1,14 @@ +# Stubs for bson.min_key (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any + +class MinKey: + def __eq__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __ne__(self, other: Any) -> bool: ... + def __le__(self, dummy: Any) -> bool: ... + def __lt__(self, other: Any) -> bool: ... + def __ge__(self, other: Any) -> bool: ... + def __gt__(self, dummy: Any) -> bool: ... diff --git a/bson/objectid.pyi b/bson/objectid.pyi new file mode 100644 index 0000000000..371bfc7ce7 --- /dev/null +++ b/bson/objectid.pyi @@ -0,0 +1,26 @@ +# Stubs for bson.objectid (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +import datetime +from typing import Any, Optional, Union + +from bson.errors import InvalidId as InvalidId + +class ObjectId: + def __init__(self, oid: Optional[Union[str, ObjectId, bytes]] = ...) -> None: ... + @classmethod + def from_datetime(cls, generation_time: datetime.datetime) -> ObjectId: ... + @classmethod + def is_valid(cls, oid: Any) -> bool: ... + @property + def binary(self) -> bytes: ... + @property + def generation_time(self) -> datetime.datetime: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __lt__(self, other: Any) -> bool: ... + def __le__(self, other: Any) -> bool: ... + def __gt__(self, other: Any) -> bool: ... + def __ge__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... diff --git a/bson/py.typed b/bson/py.typed new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bson/raw_bson.pyi b/bson/raw_bson.pyi new file mode 100644 index 0000000000..21c1a3bcec --- /dev/null +++ b/bson/raw_bson.pyi @@ -0,0 +1,16 @@ +# Stubs for bson.raw_bson (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Dict, Optional, TypeVar +from bson.codec_options import CodecOptions + +_Key = TypeVar('_Key') +_Value = TypeVar('_Value') + +class RawBSONDocument(Dict[_Key, _Value]): + def __init__(self, bson_bytes: bytes, codec_options: Optional[CodecOptions] = ...) -> None: ... + @property + def raw(self) -> bytes: ... + +DEFAULT_RAW_BSON_OPTIONS: CodecOptions diff --git a/bson/regex.pyi b/bson/regex.pyi new file mode 100644 index 0000000000..08336be0f1 --- /dev/null +++ b/bson/regex.pyi @@ -0,0 +1,17 @@ +# Stubs for bson.regex (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Pattern, Union + +def str_flags_to_int(str_flags: str) -> int: ... + +class Regex: + @classmethod + def from_native(cls, regex: Pattern[str]) -> Regex: ... + pattern: Union[str, bytes] = ... + flags: int = ... + def __init__(self, pattern: Union[str, bytes], flags: int = ...) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def try_compile(self) -> Pattern[str]: ... diff --git a/bson/son.pyi b/bson/son.pyi new file mode 100644 index 0000000000..af754cefe3 --- /dev/null +++ b/bson/son.pyi @@ -0,0 +1,25 @@ +# Stubs for bson.son (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Dict, Iterable, Iterator, List, Mapping, Optional, Tuple, TypeVar, Union + +RE_TYPE: Any + +_Key = TypeVar('_Key') +_Value = TypeVar('_Value') + +class SON(Dict[_Key, _Value]): + def __init__( + self, + data: Optional[Union[Mapping[_Key, _Value], Iterable[Tuple[_Key, _Value]]]] = ..., + **kwargs: _Value) -> None: ... + def __new__(cls, *args: Any, **kwargs: Any) -> SON[_Key, _Value]: ... + def copy(self) -> SON[_Key, _Value]: ... + def has_key(self, key: _Key) -> bool: ... + def iteritems(self) -> Iterator[Tuple[_Key, _Value]]: ... + def iterkeys(self) -> Iterator[_Key]: ... + def itervalues(self) -> Iterator[_Value]: ... + def setdefault(self, key: _Key, default: Optional[_Value] = ...) -> _Value: ... + def popitem(self) -> Tuple[_Key, _Value]: ... + def to_dict(self) -> Dict[_Key, _Value]: ... diff --git a/bson/timestamp.pyi b/bson/timestamp.pyi new file mode 100644 index 0000000000..2d8b3bc539 --- /dev/null +++ b/bson/timestamp.pyi @@ -0,0 +1,23 @@ +# Stubs for bson.timestamp (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +import datetime +from typing import Any, Union + +UPPERBOUND: int + +class Timestamp: + def __init__(self, time: Union[datetime.datetime, int], inc: int) -> None: ... + @property + def time(self) -> int: ... + @property + def inc(self) -> int: ... + def __eq__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __ne__(self, other: Any) -> bool: ... + def __lt__(self, other: Any) -> bool: ... + def __le__(self, other: Any) -> bool: ... + def __gt__(self, other: Any) -> bool: ... + def __ge__(self, other: Any) -> bool: ... + def as_datetime(self) -> datetime.datetime: ... diff --git a/bson/tz_util.pyi b/bson/tz_util.pyi new file mode 100644 index 0000000000..78c67cf0d0 --- /dev/null +++ b/bson/tz_util.pyi @@ -0,0 +1,17 @@ +# Stubs for bson.tz_util (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from datetime import datetime, timedelta, tzinfo +from typing import Optional, Tuple, Union + +ZERO: timedelta + +class FixedOffset(tzinfo): + def __init__(self, offset: Union[float, timedelta], name: str) -> None: ... + def __getinitargs__(self) -> Tuple[timedelta, str]: ... + def utcoffset(self, dt: Optional[datetime]) -> timedelta: ... + def tzname(self, dt: Optional[datetime]) -> str: ... + def dst(self, dt: Optional[datetime]) -> timedelta: ... + +utc: FixedOffset diff --git a/pymongo/__init__.pyi b/pymongo/__init__.pyi index a48c9a654a..878c62631e 100644 --- a/pymongo/__init__.pyi +++ b/pymongo/__init__.pyi @@ -1,3 +1,20 @@ +import typing +from pymongo.collection import ReturnDocument as ReturnDocument +from pymongo.common import (MIN_SUPPORTED_WIRE_VERSION as MIN_SUPPORTED_WIRE_VERSION, + MAX_SUPPORTED_WIRE_VERSION as MAX_SUPPORTED_WIRE_VERSION) +from pymongo.cursor import CursorType as CursorType +from pymongo.mongo_client import MongoClient as MongoClient +from pymongo.mongo_replica_set_client import MongoReplicaSetClient as MongoReplicaSetClient +from pymongo.operations import (IndexModel as IndexModel, + InsertOne as InsertOne, + DeleteOne as DeleteOne, + DeleteMany as DeleteMany, + UpdateOne as UpdateOne, + UpdateMany as UpdateMany, + ReplaceOne as ReplaceOne) +from pymongo.read_preferences import ReadPreference as ReadPreference +from pymongo.write_concern import WriteConcern as WriteConcern + ASCENDING: int = ... DESCENDING: int = ... GEO2D: str = ... @@ -8,28 +25,10 @@ TEXT: str = ... OFF: int = ... SLOW_ONLY: int = ... ALL: int = ... -version_tuple = (3, 5, 0, '.dev0') - +version_tuple: typing.Tuple[int, int, int, str] = ... def get_version_string() -> str: ... - __version__ = version = ... -from pymongo.collection import ReturnDocument -from pymongo.common import (MIN_SUPPORTED_WIRE_VERSION, - MAX_SUPPORTED_WIRE_VERSION) -from pymongo.cursor import CursorType -from pymongo.mongo_client import MongoClient -from pymongo.mongo_replica_set_client import MongoReplicaSetClient -from pymongo.operations import (IndexModel, - InsertOne, - DeleteOne, - DeleteMany, - UpdateOne, - UpdateMany, - ReplaceOne) -from pymongo.read_preferences import ReadPreference -from pymongo.write_concern import WriteConcern - def has_c() -> bool: ... diff --git a/pymongo/auth.pyi b/pymongo/auth.pyi index 0729977569..61edb5439e 100644 --- a/pymongo/auth.pyi +++ b/pymongo/auth.pyi @@ -2,28 +2,20 @@ from typing import Any, Dict, FrozenSet, NamedTuple from pymongo.pool import SocketInfo +HAVE_KERBEROS: bool = True MECHANISMS: FrozenSet[str] = ... -class MongoCredential(NamedTuple): - mechanism: str - source: str - username: str - password: str - props: Any -class GSSAPIProperties(NamedTuple): - service_name: str - canonicalize_host_name: bool - service_realm: Any -def _build_credentials_tuple(mech: str, source: str, user: str, passwd: str, extra: Dict[str, Any]) -> MongoCredential: ... -def _parse_scram_response(response: bytes) -> Dict[bytes, int]: ... -def _authenticate_scram_sha1(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... -def _password_digest(username: str, password: str) -> str: ... -def _auth_key(nonce: str, username: str, password: str) -> str: ... -def _authenticate_gssapi(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... -def _authenticate_plain(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... -def _authenticate_cram_md5(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... -def _authenticate_x509(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... -def _authenticate_mongo_cr(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... -def _authenticate_default(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... +MongoCredential = NamedTuple('MongoCredential', [ + ('mechanism', str), + ('source', str), + ('username', str), + ('password', str), + ('props', Any), +]) +GSSAPIProperties = NamedTuple('GSSAPIProperties', [ + ('service_name', str), + ('canonicalize_host_name', bool), + ('service_realm', Any), +]) def authenticate(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... def logout(source: str, sock_info: SocketInfo) -> None: ... diff --git a/pymongo/bulk.pyi b/pymongo/bulk.pyi index e5b8bd8d8e..0f1403b9c1 100644 --- a/pymongo/bulk.pyi +++ b/pymongo/bulk.pyi @@ -2,6 +2,10 @@ from typing import Any, Dict, Iterator, List, Optional, Tuple, Union from pymongo.collation import Collation from pymongo.collection import Collection +from pymongo.errors import (BulkWriteError as BulkWriteError, + ConfigurationError as ConfigurationError, + InvalidOperation as InvalidOperation, + OperationFailure as OperationFailure) from pymongo.pool import SocketInfo from pymongo.write_concern import WriteConcern @@ -22,19 +26,31 @@ class _Run(object): def __init__(self, op_type: int) -> None: ... def index(self, idx: int) -> int: ... def add(self, original_index: int, operation: Dict[str, Any]) -> None: ... -def _make_error(index: int, code: int, errmsg: str, operation: Dict[str, Any]) -> Dict[str, Any]: ... -def _merge_legacy(run: _Run, full_result: Dict[str, Any], result: Dict[str, Any], index: int) -> None: ... -def _merge_command(run: _Run, full_result: Dict[str, Any], results: List[Tuple[int, Dict[str, Any]]]) -> None: ... class _Bulk(object): def __init__(self, collection: Collection, ordered: bool, bypass_document_validation: bool) -> None: ... def add_insert(self, document: Dict[str, Any]) -> None: ... - def add_update(self, selector: Dict[str, Any], update: Dict[str, Any], multi: bool = ..., upsert: bool = ..., collation: Optional[Collation] = ...) -> None: ... - def add_replace(self, selector: Dict[str, Any], replacement: Dict[str, Any], upsert: bool = ..., collation: Optional[Collation] = ...) -> None: ... + def add_update( + self, + selector: Dict[str, Any], + update: Dict[str, Any], + multi: bool = ..., + upsert: bool = ..., + collation: Optional[Collation] = ...) -> None: ... + def add_replace( + self, + selector: Dict[str, Any], + replacement: Dict[str, Any], + upsert: bool = ..., + collation: Optional[Collation] = ...) -> None: ... def add_delete(self, selector: Dict[str, Any], limit: int, collation: Optional[Collation] = ...) -> None: ... def gen_ordered(self) -> _Run: ... def gen_unordered(self) -> _Run: ... - def execute_command(self, sock_info: SocketInfo, generator: Iterator[_Run], write_concern: WriteConcern) -> Dict[str, Any]: ... + def execute_command( + self, + sock_info: SocketInfo, + generator: Iterator[_Run], + write_concern: WriteConcern) -> Dict[str, Any]: ... def execute_no_results(self, sock_info: SocketInfo, generator: Iterator[_Run]) -> None: ... def execute_legacy(self, sock_info: SocketInfo, generator: Iterator[_Run], write_concern: WriteConcern) -> None: ... def execute(self, write_concern: WriteConcern) -> Union[Dict[str, Any], None]: ... @@ -58,4 +74,4 @@ class BulkOperationBuilder(object): def __init__(self, collection: Collection, ordered: bool = ..., bypass_document_validation: bool = ...) -> None: ... def find(self, selector: Dict[str, Any], collation: Optional[Collation] = ...) -> BulkWriteOperation: ... def insert(self, document: Dict[str, Any]) -> None: ... - def execute(self, write_concern: Optional[WriteConcern] = None) -> Union[Dict[str, Any], None]: ... + def execute(self, write_concern: Optional[WriteConcern] = ...) -> Union[Dict[str, Any], None]: ... diff --git a/pymongo/change_stream.pyi b/pymongo/change_stream.pyi new file mode 100644 index 0000000000..a7d1799b12 --- /dev/null +++ b/pymongo/change_stream.pyi @@ -0,0 +1,31 @@ +# Stubs for pymongo.change_stream (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from bson.timestamp import Timestamp +from pymongo.collation import Collation +from pymongo.client_session import ClientSession +from typing import Any, Mapping, Optional, Sequence + +class ChangeStream: + def __init__( + self, + target: Any, + pipeline: Optional[Sequence[Mapping[str, Any]]], + full_document: str, + resume_after: Optional[str], + max_await_time_ms: Optional[int], + batch_size: Optional[int], + collation: Optional[Collation], + start_at_operation_time: Optional[Timestamp], + session: Optional[ClientSession]) -> None: ... + def close(self) -> None: ... + def __iter__(self) -> ChangeStream: ... + def next(self) -> Mapping[str, Any]: ... + def __next__(self) -> Mapping[str, Any]: ... + def __enter__(self) -> ChangeStream: ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... + +class CollectionChangeStream(ChangeStream): ... +class DatabaseChangeStream(ChangeStream): ... +class ClusterChangeStream(DatabaseChangeStream): ... diff --git a/pymongo/client_options.pyi b/pymongo/client_options.pyi index 41ef89548b..1995dabc50 100644 --- a/pymongo/client_options.pyi +++ b/pymongo/client_options.pyi @@ -9,18 +9,9 @@ from pymongo.ssl_support import SSLContext from pymongo.write_concern import WriteConcern -def _parse_credentials(username: str, password: str, database: str, options: Dict[str, Any]) -> Optional[MongoCredential]: ... -def _parse_read_preference(options: Dict[str, Any]) -> _ServerMode: ... -def _parse_write_concern(options: Dict[str, Any]) -> WriteConcern: ... -def _parse_read_concern(options: Dict[str, Any]) -> ReadConcern: ... -def _parse_ssl_options(options: Dict[str, Any]) -> Tuple[Optional[SSLContext], bool]: ... -def _parse_pool_options(options: Dict[str, Any]) -> PoolOptions: ... - class ClientOptions(object): def __init__(self, username: str, password: str, database: str, options: Dict[str, Any]) -> None: ... @property - def _options(self) -> Dict[str, Any]: ... - @property def connect(self) -> bool: ... @property def codec_options(self) -> CodecOptions: ... diff --git a/pymongo/client_session.pyi b/pymongo/client_session.pyi new file mode 100644 index 0000000000..7bdd9bfc7c --- /dev/null +++ b/pymongo/client_session.pyi @@ -0,0 +1,74 @@ +# Stubs for pymongo.client_session (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from bson.binary import Binary +from bson.int64 import Int64 +from bson.timestamp import Timestamp +from pymongo.mongo_client import MongoClient +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.write_concern import WriteConcern +from typing import Any, Dict, Mapping, Optional + +class SessionOptions: + def __init__( + self, + causal_consistency: bool = ..., + default_transaction_options: Optional[TransactionOptions] = ...) -> None: ... + @property + def causal_consistency(self) -> bool: ... + @property + def default_transaction_options(self) -> Optional[TransactionOptions]: ... + +class TransactionOptions: + def __init__( + self, + read_concern: Optional[ReadConcern] = ..., + write_concern: Optional[WriteConcern] = ..., + read_preference: Optional[_ServerMode] = ...) -> None: ... + @property + def read_concern(self) -> ReadConcern: ... + @property + def write_concern(self) -> WriteConcern: ... + @property + def read_preference(self) -> _ServerMode: ... + +class _TransactionContext: + def __init__(self, session: ClientSession) -> None: ... + def __enter__(self) -> _TransactionContext: ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... + +class ClientSession: + def __init__(self, client: MongoClient, server_session: ServerSession, options: Any, authset: Any, implicit: Any) -> None: ... + def end_session(self) -> None: ... + def __enter__(self) -> ClientSession: ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... + @property + def client(self) -> MongoClient: ... + @property + def options(self) -> SessionOptions: ... + @property + def session_id(self) -> Dict[str, Binary]: ... + @property + def cluster_time(self) -> Mapping[str, Timestamp]: ... + @property + def operation_time(self) -> Timestamp: ... + def start_transaction( + self, + read_concern: Optional[ReadConcern] = ..., + write_concern: Optional[WriteConcern] = ..., + read_preference: Optional[_ServerMode] = ...) -> _TransactionContext: ... + def commit_transaction(self) -> None: ... + def abort_transaction(self) -> None: ... + def advance_cluster_time(self, cluster_time: Mapping[str, Timestamp]) -> None: ... + def advance_operation_time(self, operation_time: Timestamp) -> None: ... + @property + def has_ended(self) -> bool: ... + +class ServerSession: + def __init__(self) -> None: ... + def timed_out(self, session_timeout_minutes: int) -> bool: ... + @property + def transaction_id(self) -> Int64: ... + def inc_transaction_id(self) -> None: ... diff --git a/pymongo/collation.pyi b/pymongo/collation.pyi index ad3314e032..71b8f21ffa 100644 --- a/pymongo/collation.pyi +++ b/pymongo/collation.pyi @@ -18,7 +18,18 @@ class CollationCaseFirst(object): LOWER: str = ... OFF: str = ... class Collation(object): - def __init__(self, locale: str, caseLevel: Optional[bool] = ..., caseFirst: Optional[str] = ..., strength: Optional[int] = ..., numericOrdering: Optional[bool] = ..., alternate: Optional[str] = ..., maxVariable: Optional[str] = ..., normalization: Optional[bool] = ..., backwards: Optional[bool] = ..., **kwargs: Any) -> None: ... + def __init__( + self, + locale: str, + caseLevel: Optional[bool] = ..., + caseFirst: Optional[str] = ..., + strength: Optional[int] = ..., + numericOrdering: Optional[bool] = ..., + alternate: Optional[str] = ..., + maxVariable: Optional[str] = ..., + normalization: Optional[bool] = ..., + backwards: Optional[bool] = ..., + **kwargs: Any) -> None: ... @property def document(self) -> Dict[str, Any]: ... def __repr__(self) -> str: ... diff --git a/pymongo/collection.pyi b/pymongo/collection.pyi index 55abbbac26..5f08195277 100644 --- a/pymongo/collection.pyi +++ b/pymongo/collection.pyi @@ -2,11 +2,14 @@ from typing import (Any, Callable, Dict, Iterable, Iterator, List, Mapping, Optional, Sequence, Tuple, Union) from bson.codec_options import CodecOptions +from bson.timestamp import Timestamp from pymongo.bulk import BulkOperationBuilder +from pymongo.change_stream import CollectionChangeStream +from pymongo.client_session import ClientSession from pymongo.collation import Collation from pymongo.command_cursor import CommandCursor from pymongo.common import BaseObject -from pymongo.cursor import Cursor +from pymongo.cursor import Cursor, RawBatchCursor from pymongo.database import Database from pymongo.operations import IndexModel, _WriteOp from pymongo.pool import SocketInfo @@ -21,11 +24,17 @@ class ReturnDocument(object): BEFORE: bool = ... AFTER: bool = ... class Collection(BaseObject): - def __init__(self, database: Database, name: str, create: Optional[bool] = ..., codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ..., **kwargs: Any) -> None: ... - def _socket_for_reads(self) -> Iterator[Tuple[SocketInfo, bool]]: ... - def _socket_for_primary_reads(self) -> Iterator[Tuple[SocketInfo, bool]]: ... - def _socket_for_writes(self) -> Iterator[SocketInfo]: ... - def _command(self, sock_info: SocketInfo, command: Mapping[str, Any], slave_ok: bool = ..., read_preference: Optional[_ServerMode] = ..., codec_options: Optional[CodecOptions] = ..., check: bool = ..., allowable_errors: Optional[Sequence[str]] = ..., read_concern: Optional[ReadConcern] = ..., write_concern: Optional[WriteConcern] = ..., parse_write_concern_error: bool = ..., collation: Optional[Collation] = ...) -> Dict[str, Any]: ... + def __init__( + self, + database: Database, + name: str, + create: Optional[bool] = ..., + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> None: ... def __create(self, options: Mapping[str, Any], collation: Collation) -> None: ... def __getattr__(self, name: str) -> 'Collection': ... def __getitem__(self, name: str) -> 'Collection': ... @@ -38,54 +47,198 @@ class Collection(BaseObject): def name(self) -> str: ... @property def database(self) -> Database: ... - def with_options(self, codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ...) -> 'Collection': ... + def with_options( + self, + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ...) -> 'Collection': ... def initialize_unordered_bulk_op(self, bypass_document_validation: bool = ...) -> BulkOperationBuilder: ... def initialize_ordered_bulk_op(self, bypass_document_validation: bool = ...) -> BulkOperationBuilder: ... - def bulk_write(self, requests: Sequence[_WriteOp], ordered: bool = ..., bypass_document_validation: bool = ...) -> BulkWriteResult: ... - def _legacy_write(self, sock_info: SocketInfo, name: str, cmd: Mapping[str, Any], acknowledged: bool, op_id: int, bypass_doc_val: bool, func: Callable[[Any], Any], *args: Any) -> Dict[str, Any]: ... - def _insert_one(self, sock_info: SocketInfo, doc: Mapping[str, Any], ordered: bool, check_keys: bool, manipulate: bool, write_concern: WriteConcern, op_id: int, bypass_doc_val: bool) -> Any: ... - def _insert(self, sock_info: SocketInfo, docs: Union[Mapping[str, Any], Sequence[Mapping[str, Any]]], ordered: bool = ..., check_keys: bool = ..., manipulate: bool = ..., write_concern: Optional[WriteConcern] = ..., op_id: Optional[int] = ..., bypass_doc_val: bool = ...) -> Any: ... - def insert_one(self, document: Any, bypass_document_validation: bool = ...) -> InsertOneResult: ... - def insert_many(self, documents: Iterable[Any], ordered: bool = ..., bypass_document_validation: bool = ...) -> InsertManyResult: ... - def _update(self, sock_info: SocketInfo, criteria: Mapping[str, Any], document: Mapping[str, Any], upsert: bool = ..., check_keys: bool = ..., multi: bool = ..., manipulate: bool = ..., write_concern: Optional[WriteConcern] = ..., op_id: Optional[int] = ..., ordered: bool = ..., bypass_doc_val: bool = ..., collation: Optional[Collation] = ...) -> Dict[str, Any]: ... - def replace_one(self, filter: Mapping[str, Any], replacement: Mapping[str, Any], upsert: bool = ..., bypass_document_validation: bool = ..., collation: Optional[Collation] = ...) -> UpdateResult: ... - def update_one(self, filter: Mapping[str, Any], update: Mapping[str, Any], upsert: bool = ..., bypass_document_validation: bool = ..., collation: Optional[Collation] = ...) -> UpdateResult: ... - def update_many(self, filter: Mapping[str, Any], update: Mapping[str, Any], upsert: bool = ..., bypass_document_validation: bool = ..., collation: Optional[Collation] = ...) -> UpdateResult: ... - def drop(self) -> None: ... - def _delete(self, sock_info: SocketInfo, criteria: Mapping[str, Any], multi: bool, write_concern: Optional[WriteConcern] = ..., op_id: Optional[int] = ..., ordered: bool = ..., collation: Optional[Collation] = ...) -> Dict[str, Any]: ... - def delete_one(self, filter: Mapping[str, Any], collation: Optional[Collation] = ...) -> DeleteResult: ... - def delete_many(self, filter: Mapping[str, Any], collation: Optional[Collation] = ...) -> DeleteResult: ... + def bulk_write( + self, + requests: Sequence[_WriteOp], + ordered: bool = ..., + bypass_document_validation: bool = ..., + session: Optional[ClientSession] = ...) -> BulkWriteResult: ... + def insert_one( + self, + document: Any, + bypass_document_validation: bool = ..., + session: Optional[ClientSession] = ...) -> InsertOneResult: ... + def insert_many( + self, + documents: Iterable[Any], + ordered: bool = ..., + bypass_document_validation: bool = ..., + session: Optional[ClientSession] = ...) -> InsertManyResult: ... + def replace_one( + self, + filter: Mapping[str, Any], + replacement: Mapping[str, Any], + upsert: bool = ..., + bypass_document_validation: bool = ..., + collation: Optional[Collation] = ..., + session: Optional[ClientSession] = ...) -> UpdateResult: ... + def update_one( + self, + filter: Mapping[str, Any], + update: Mapping[str, Any], + upsert: bool = ..., + bypass_document_validation: bool = ..., + collation: Optional[Collation] = ..., + array_filters: Optional[List[Mapping[str, Any]]] = ..., + session: Optional[ClientSession] = ...) -> UpdateResult: ... + def update_many( + self, + filter: Mapping[str, Any], + update: Mapping[str, Any], + upsert: bool = ..., + array_filters: Optional[List[Mapping[str, Any]]] = ..., + bypass_document_validation: bool = ..., + collation: Optional[Collation] = ..., + session: Optional[ClientSession] = ...) -> UpdateResult: ... + def drop(self, session: Optional[ClientSession] = ...) -> None: ... + def delete_one( + self, + filter: Mapping[str, Any], + collation: Optional[Collation] = ..., + session: Optional[ClientSession] = ...) -> DeleteResult: ... + def delete_many( + self, + filter: Mapping[str, Any], + collation: Optional[Collation] = ..., + session: Optional[ClientSession] = ...) -> DeleteResult: ... def find_one(self, filter: Optional[Mapping[str, Any]] = ..., *args: Any, **kwargs: Any) -> Optional[Dict[str, Any]]: ... def find(self, *args: Any, **kwargs: Any) -> Cursor: ... - def parallel_scan(self, num_cursors: int, **kwargs: Any) -> List[CommandCursor]: ... - def _count(self, cmd: Mapping[str, Any], collation: Optional[Collation] = ...) -> int: ... - def count(self, filter: Optional[Mapping[str, Any]] = ..., **kwargs: Any) -> int: ... - def create_indexes(self, indexes: Sequence[IndexModel], **kwargs: Any) -> List[str]: ... - def __create_index(self, keys: Sequence[Tuple[str, Union[int, str]]], index_options: Mapping[str, Any]) -> None: ... - def create_index(self, keys: Union[str, Sequence[Tuple[str, Union[int, str]]]], **kwargs: Any) -> str: ... - def ensure_index(self, key_or_list: Union[str, Sequence[Tuple[str, Union[int, str]]]], cache_for: int = ..., **kwargs: Any) -> Optional[str]: ... - def drop_indexes(self) -> None: ... - def drop_index(self, index_or_name: Union[str, Sequence[Tuple[Any, Any]]]) -> None: ... - def reindex(self) -> Dict[str, Any]: ... - def list_indexes(self) -> CommandCursor: ... - def index_information(self) -> Dict[str, Any]: ... - def options(self) -> Dict[str, Any]: ... - def _aggregate(self, pipeline: Sequence[Mapping[str, Any]], **kwargs: Any) -> CommandCursor: ... - def aggregate(self, pipeline: Sequence[Mapping[str, Any]], **kwargs: Any) -> CommandCursor: ... - def group(self, key: Mapping[str, Any], condition: Mapping[str, Any], initial: Mapping[str, int], reduce: str, finalize: str = ..., **kwargs: Any) -> List[Dict[str, Any]]: ... - def rename(self, new_name: str, **kwargs: Any) -> None: ... - def distinct(self, key: str, filter: Optional[Mapping[str, Any]] = ..., **kwargs: Any) -> List[Any]: ... - def map_reduce(self, map: str, reduce: str, out: Union[str, Mapping[str, Any]], full_response: bool = ..., **kwargs: Any) -> Union[Dict[str, Any], Database, 'Collection']: ... - def inline_map_reduce(self, map: str, reduce: str, full_response: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... - def __find_and_modify(self, filter: Mapping[str, Any], projection: Union[Sequence[str], Mapping[str, bool]], sort: Sequence[Tuple[str, Union[int, str]]], upsert: Optional[bool] = ..., return_document: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... - def find_one_and_delete(self, filter: Mapping[str, Any], projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., **kwargs: Any) -> Dict[str, Any]: ... - def find_one_and_replace(self, filter: Mapping[str, Any], replacement: Mapping[str, Any], projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., upsert: bool = ..., return_document: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... - def find_one_and_update(self, filter: Mapping[str, Any], update: Mapping[str, Any], projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., upsert: bool = ..., return_document: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... + def find_raw_batches(self, *args: Any, **kwargs: Any) -> RawBatchCursor: ... + def parallel_scan(self, num_cursors: int, session: Optional[ClientSession] = ..., **kwargs: Any) -> List[CommandCursor]: ... + def estimated_document_count(self, **kwargs: Any) -> int: ... + def count(self, filter: Optional[Mapping[str, Any]] = ..., session: Optional[ClientSession] = ..., **kwargs: Any) -> int: ... + def count_documents(self, filter: Mapping[str, Any], session: Optional[ClientSession] = ..., **kwargs: Any) -> int: ... + def create_indexes( + self, + indexes: Sequence[IndexModel], + session: Optional[ClientSession] = ..., + **kwargs: Any) -> List[str]: ... + def create_index( + self, + keys: Union[str, Sequence[Tuple[str, Union[int, str]]], Mapping[str, Union[int, str]]], + session: Optional[ClientSession] = ..., + **kwargs: Any) -> str: ... + def ensure_index( + self, + key_or_list: Union[str, Sequence[Tuple[str, Union[int, str]]]], + cache_for: int = ..., + **kwargs: Any) -> Optional[str]: ... + def drop_indexes(self, session: Optional[ClientSession] = ...) -> None: ... + def drop_index( + self, + index_or_name: Union[str, Sequence[Tuple[Any, Any]]], + session: Optional[ClientSession] = ...) -> None: ... + def reindex(self, session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def list_indexes(self, session: Optional[ClientSession] = ...) -> CommandCursor: ... + def index_information(self, session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def options(self, session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def aggregate( + self, + pipeline: Sequence[Mapping[str, Any]], + session: Optional[ClientSession] = ..., + **kwargs: Any) -> CommandCursor: ... + def aggregate_raw_batches(self, pipeline: Sequence[Mapping[str, Any]], **kwargs: Any) -> RawBatchCursor: ... + def watch( + self, + pipeline: Optional[Sequence[Mapping[str, Any]]], + full_document: str = ..., + resume_after: Optional[str] = ..., + max_await_time_ms: Optional[int] = ..., + batch_size: Optional[int] = ..., + collation: Optional[Collation] = ..., + start_at_operation_time: Optional[Timestamp] = ..., + session: Optional[ClientSession] = ...) -> CollectionChangeStream: ... + def group( + self, + key: Mapping[str, Any], + condition: Mapping[str, Any], + initial: Mapping[str, int], + reduce: str, + finalize: str = ..., + **kwargs: Any) -> List[Dict[str, Any]]: ... + def rename(self, new_name: str, session: Optional[ClientSession] = ..., **kwargs: Any) -> None: ... + def distinct( + self, + key: str, + filter: Optional[Mapping[str, Any]] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> List[Any]: ... + def map_reduce( + self, + map: str, + reduce: str, + out: Union[str, Mapping[str, Any]], + full_response: bool = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Union[Dict[str, Any], Database, 'Collection']: ... + def inline_map_reduce( + self, + map: str, + reduce: str, + full_response: bool = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Dict[str, Any]: ... + def find_one_and_delete( + self, + filter: Mapping[str, Any], + projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., + sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Dict[str, Any]: ... + def find_one_and_replace( + self, + filter: Mapping[str, Any], + replacement: Mapping[str, Any], + projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., + sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., + upsert: bool = ..., + return_document: bool = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Dict[str, Any]: ... + def find_one_and_update( + self, + filter: Mapping[str, Any], + update: Mapping[str, Any], + projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., + sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., + upsert: bool = ..., + return_document: bool = ..., + array_filters: Optional[List[Mapping[str, Any]]] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Dict[str, Any]: ... def save(self, to_save: Mapping[str, Any], manipulate: bool = ..., check_keys: bool = ..., **kwargs: Any) -> Any: ... - def insert(self, doc_or_docs: Mapping[str, Any], manipulate: bool = ..., check_keys: bool = ..., continue_on_error: bool = ..., **kwargs: Any) -> Any: ... - def update(self, spec: Mapping[str, Any], document: Mapping[str, Any], upsert: bool = ..., manipulate: bool = ..., multi: bool = ..., check_keys: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... + def insert( + self, + doc_or_docs: Mapping[str, Any], + manipulate: bool = ..., + check_keys: bool = ..., + continue_on_error: bool = ..., + **kwargs: Any) -> Any: ... + def update( + self, + spec: Mapping[str, Any], + document: Mapping[str, Any], + upsert: bool = ..., + manipulate: bool = ..., + multi: bool = ..., + check_keys: bool = ..., + **kwargs: Any) -> Dict[str, Any]: ... def remove(self, spec_or_id: Optional[Mapping[str, Any]] = ..., multi: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... - def find_and_modify(self, query: Mapping[str, Any] = {}, update: Mapping[str, Any] = ..., upsert: bool = ..., sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., full_response: bool = ..., manipulate: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... - def __iter__(self) -> 'Collection': ... - def __next__(self) -> None: ... + def find_and_modify( + self, + query: Mapping[str, Any] = ..., + update: Mapping[str, Any] = ..., + upsert: bool = ..., + sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., + full_response: bool = ..., + manipulate: bool = ..., + **kwargs: Any) -> Dict[str, Any]: ... def __call__(self, *args: Any, **kwargs: Any) -> None: ... diff --git a/pymongo/command_cursor.pyi b/pymongo/command_cursor.pyi index 300d42f070..f578acfcd9 100644 --- a/pymongo/command_cursor.pyi +++ b/pymongo/command_cursor.pyi @@ -1,17 +1,27 @@ from typing import Any, Dict, Tuple, Union from pymongo import message +from pymongo.client_session import ClientSession from pymongo.collection import Collection +from typing import Optional class CommandCursor(object): - def __init__(self, collection: Collection, cursor_info: Dict[str, Any], address: Tuple[str, int], retrieved: int = ...) -> None: ... + def __init__( + self, + collection: Collection, + cursor_info: Dict[str, Any], + address: Tuple[str, int], + retrieved: int = ..., + batch_size: int = ..., + max_await_time_ms: Optional[int] = ..., + session: Optional[ClientSession] = ..., + explicit_session: bool = ...) -> None: ... def __del__(self) -> None: ... def __die(self) -> None: ... def close(self) -> None: ... def batch_size(self, batch_size: int) -> 'CommandCursor': ... def __send_message(self, operation: Union[message._Query, message._GetMore]) -> None: ... - def _refresh(self) -> int: ... @property def alive(self) -> bool: ... @property @@ -20,5 +30,6 @@ class CommandCursor(object): def address(self) -> Tuple[str, int]: ... def __iter__(self) -> 'CommandCursor': ... def next(self) -> Dict[str, Any]: ... + def __next__(self) -> Dict[str, Any]: ... def __enter__(self) -> 'CommandCursor': ... def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... diff --git a/pymongo/common.pyi b/pymongo/common.pyi index 78967d2b41..74e3cca198 100644 --- a/pymongo/common.pyi +++ b/pymongo/common.pyi @@ -1,8 +1,9 @@ import collections import datetime -from typing import Any, Callable, Dict, FrozenSet, List, Mapping, Optional, Tuple, Union +from typing import Any, Callable, Dict, FrozenSet, List, Mapping, MutableMapping, Optional, Tuple, Type, TypeVar, Union from bson import CodecOptions +from bson.raw_bson import RawBSONDocument from pymongo.read_concern import ReadConcern from pymongo.read_preferences import _ServerMode from pymongo.write_concern import WriteConcern @@ -55,7 +56,8 @@ def validate_auth_mechanism(option: str, value: Any) -> str: ... def validate_uuid_representation(dummy: Any, value: Any) -> int: ... def validate_read_preference_tags(name: str, value: Any) -> List[Dict[str, str]]: ... def validate_auth_mechanism_properties(option: str, value: Any) -> Dict[str, Union[bool, str]]: ... -def validate_document_class(option: str, value: Any) -> Union[collections.MutableMapping, collections.Mapping]: ... +_DocumentClass = TypeVar('_DocumentClass', Type[RawBSONDocument[str, Any]], Type[MutableMapping[str, Any]]) +def validate_document_class(option: str, value: _DocumentClass) -> _DocumentClass: ... def validate_list(option: str, value: Any) -> List[Any]: ... def validate_is_mapping(option: str, value: Any) -> Dict[Any, Any]: ... def validate_is_document_type(option: str, value: Any) -> None: ... @@ -71,9 +73,14 @@ VALIDATORS: Dict[str, Callable[..., Any]] = ... _AUTH_OPTIONS: FrozenSet[str] = ... def validate_auth_option(option: str, value: Any) -> Tuple[str, Any]: ... def validate(option: str, value: Any) -> Tuple[str, Any]: ... -def get_validated_options(options: Mapping[str, Any], warn: bool = True) -> Dict[str, Any]: ... +def get_validated_options(options: Mapping[str, Any], warn: bool = ...) -> Dict[str, Any]: ... class BaseObject(object): - def __init__(self, codec_options: CodecOptions, read_preference: _ServerMode, write_concern: WriteConcern, read_concern: ReadConcern) -> None: ... + def __init__( + self, + codec_options: CodecOptions, + read_preference: _ServerMode, + write_concern: WriteConcern, + read_concern: ReadConcern) -> None: ... @property def codec_options(self) -> CodecOptions: ... @property diff --git a/pymongo/compression_support.pyi b/pymongo/compression_support.pyi new file mode 100644 index 0000000000..54b5b81aa0 --- /dev/null +++ b/pymongo/compression_support.pyi @@ -0,0 +1,27 @@ +# Stubs for pymongo.compression_support (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Iterable, List, Sequence, Union + +def validate_compressors(dummy: Any, value: Union[str, Iterable[str]]) -> List[str]: ... +def validate_zlib_compression_level(option: str, value: Any) -> int: ... + +class CompressionSettings: + compressors: Sequence[str] = ... + zlib_compression_level: int = ... + def __init__(self, compressors: Sequence[str], zlib_compression_level: int) -> None: ... + def get_compression_context(self, compressors: Sequence[str]) -> Union[SnappyContext, ZlibContext]: ... + +class SnappyContext: + compressor_id: int = ... + @staticmethod + def compress(data: bytes) -> bytes: ... + +class ZlibContext: + compressor_id: int = ... + @staticmethod + def compress(data: bytes) -> bytes: ... + def __init__(self, level: int) -> None: ... + +def decompress(data: bytes, compressor_id: int) -> bytes: ... diff --git a/pymongo/cursor.pyi b/pymongo/cursor.pyi index e564c7ad0c..5309a24add 100644 --- a/pymongo/cursor.pyi +++ b/pymongo/cursor.pyi @@ -1,5 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union +from pymongo.client_session import ClientSession from pymongo.collation import Collation from pymongo.collection import Collection from pymongo.message import _GetMore, _Query @@ -18,7 +19,32 @@ class _SocketManager: def close(self) -> None: ... class Cursor(object): - def __init__(self, collection: Collection, filter: Mapping[str, Any] = ..., projection: Mapping[str, Any] = ..., skip: int = ..., limit: int = ..., no_cursor_timeout: bool = ..., cursor_type: int = ..., sort: Optional[Sequence[Tuple[str, Any]]] = ..., allow_partial_results: bool = ..., oplog_replay: bool = ..., modifiers: Optional[Mapping[str, Any]] = ..., batch_size: int = ..., manipulate: bool = ..., collation: Optional[Mapping[str, Any]] = ...) -> None: ... + def __init__( + self, + collection: Collection, + filter: Mapping[str, Any] = ..., + projection: Mapping[str, Any] = ..., + skip: int = ..., + limit: int = ..., + no_cursor_timeout: bool = ..., + cursor_type: int = ..., + sort: Optional[Sequence[Tuple[str, Any]]] = ..., + allow_partial_results: bool = ..., + oplog_replay: bool = ..., + modifiers: Optional[Mapping[str, Any]] = ..., + batch_size: int = ..., + manipulate: bool = ..., + collation: Optional[Mapping[str, Any]] = ..., + hint: Optional[Union[str, Tuple[str, Union[int, str]]]] = ..., + max_scan: Optional[int] = ..., + max_time_ms: Optional[int] = ..., + max: Optional[Sequence[Tuple[str, int]]] = ..., + min: Optional[Sequence[Tuple[str, int]]] = ..., + return_key: bool = ..., + show_record_id: bool = ..., + snapshot: bool = ..., + comment: Optional[Union[str, Mapping[str, Any]]] = ..., + session: Optional[ClientSession] = ...) -> None: ... @property def collection(self) -> Collection: ... @property @@ -26,12 +52,7 @@ class Cursor(object): def __del__(self) -> None: ... def rewind(self) -> 'Cursor': ... def clone(self) -> 'Cursor': ... - def _clone(self, deepcopy: bool = ...) -> 'Cursor': ... - def _clone_base(self) -> 'Cursor': ... - def __die(self, synchronous: bool = ...) -> None: ... def close(self) -> None: ... - def __query_spec(self) -> Dict[str, Any]: ... - def __check_okay_to_chain(self) -> None: ... def add_option(self, mask: int) -> 'Cursor': ... def remove_option(self, mask: int) -> 'Cursor': ... def limit(self, limit: int) -> 'Cursor': ... @@ -43,16 +64,17 @@ class Cursor(object): def max_scan(self, max_scan: int) -> 'Cursor': ... def max(self, spec: Sequence[Tuple[str, int]]) -> 'Cursor': ... def min(self, spec: Sequence[Tuple[str, int]]) -> 'Cursor': ... - def sort(self, key_or_list: Union[str, Sequence[Tuple[str, Union[int, str]]]], direction: Optional[Union[int, str]] = ...) -> 'Cursor': ... + def sort( + self, + key_or_list: Union[str, Sequence[Tuple[str, Union[int, str]]]], + direction: Optional[Union[int, str]] = ...) -> 'Cursor': ... def count(self, with_limit_and_skip: bool = ...) -> int: ... def distinct(self, key: str) -> List[Any]: ... def explain(self) -> Dict[str, Any]: ... - def hint(self, index: Union[str, Tuple[str, Union[int, str]]]): ... + def hint(self, index: Union[str, Tuple[str, Union[int, str]]]) -> Cursor: ... def comment(self, comment: Union[str, Mapping[str, Any]]) -> 'Cursor': ... def where(self, code: str) -> 'Cursor': ... def collation(self, collation: Collation) -> 'Cursor': ... - def __send_message(self, operation: Union[None, _GetMore, _Query]) -> None: ... - def _refresh(self) -> int: ... @property def alive(self) -> bool: ... @property @@ -61,8 +83,10 @@ class Cursor(object): def address(self) -> Tuple[str, int]: ... def __iter__(self) -> 'Cursor': ... def next(self) -> Dict[str, Any]: ... + def __next__(self) -> Dict[str, Any]: ... def __enter__(self) -> 'Cursor': ... def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... def __copy__(self) -> 'Cursor': ... def __deepcopy__(self, memo: Any) -> 'Cursor': ... - def _deepcopy(self, x: Mapping[str, Any], memo: Optional[Mapping[int, Any]] = ...) -> Union[List[Any], Dict[Any, Any]]: ... + +class RawBatchCursor(Cursor): ... diff --git a/pymongo/database.pyi b/pymongo/database.pyi index 8daaadf45e..1d0c46902f 100644 --- a/pymongo/database.pyi +++ b/pymongo/database.pyi @@ -1,7 +1,11 @@ from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Union from bson import CodecOptions, DBRef +from bson.timestamp import Timestamp from pymongo import MongoClient, common +from pymongo.change_stream import DatabaseChangeStream +from pymongo.client_session import ClientSession +from pymongo.collation import Collation from pymongo.collection import Collection from pymongo.command_cursor import CommandCursor from pymongo.pool import SocketInfo @@ -11,11 +15,16 @@ from pymongo.son_manipulator import SONManipulator from pymongo.write_concern import WriteConcern -def _check_name(name: str) -> None: ... - class Database(common.BaseObject): - def __init__(self, client: MongoClient, name: str, codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ...) -> None: ... - def add_son_manipulator(self, manipulator: SONManipulator): ... + def __init__( + self, + client: MongoClient, + name: str, + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ...) -> None: ... + def add_son_manipulator(self, manipulator: SONManipulator) -> None: ... @property def system_js(self) -> SystemJS: ... @property @@ -35,39 +44,83 @@ class Database(common.BaseObject): def __repr__(self) -> str: ... def __getattr__(self, name: str) -> Collection: ... def __getitem__(self, name: str) -> Collection: ... - def get_collection(self, name: str, codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ...) -> Collection: ... - def _collection_default_options(self, name: str, **kargs: Any) -> Collection: ... - def create_collection(self, name: str, codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ..., **kwargs: Any) -> Collection: ... - def _apply_incoming_manipulators(self, son: Mapping[str, Any], collection: Collection) -> Mapping[str, Any]: ... - def _apply_incoming_copying_manipulators(self, son: Mapping[str, Any], collection: Collection) -> Mapping[str, Any]: ... - def _fix_incoming(self, son: Mapping[str, Any], collection: Collection) -> Mapping[str, Any]: ... - def _fix_outgoing(self, son: Mapping[str, Any], collection: Collection) -> Mapping[str, Any]: ... - def _command(self, sock_info: SocketInfo, command: Union[str, Mapping[str, Any]], slave_ok: bool = ..., value: int = ..., check: bool = ..., allowable_errors: Optional[Sequence[str]] = ..., read_preference: _ServerMode = ..., codec_options: CodecOptions = ..., write_concern: Optional[WriteConcern] = ..., parse_write_concern_error: bool = ..., **kwargs: Any) -> Any: ... - def command(self, command: Union[str, Mapping[str, Any]], value: int = ..., check: bool = ..., allowable_errors: Optional[Sequence[str]] = ..., read_preference: _ServerMode = ..., codec_options: CodecOptions = ..., **kwargs: Any) -> Any: ... - def _list_collections(self, sock_info: SocketInfo, slave_okay: bool, criteria: Mapping[str, Any] = ...) -> CommandCursor: ... - def collection_names(self, include_system_collections: bool = ...) -> List[str]: ... - def drop_collection(self, name_or_collection: Union[str, Collection]) -> Dict[str, Any]: ... - def validate_collection(self, name_or_collection: Union[str, Collection], scandata: bool = ..., full: bool = ...) -> Dict[str, Any]: ... - def current_op(self, include_all: bool = ...) -> Dict[str, Any]: ... - def profiling_level(self) -> int: ... - def set_profiling_level(self, level: int, slow_ms: Optional[int] = ...) -> None: ... - def profiling_info(self) -> List[Any]: ... + def get_collection( + self, + name: str, + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ...) -> Collection: ... + def create_collection( + self, + name: str, + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Collection: ... + def watch( + self, + pipeline: Optional[Sequence[Mapping[str, Any]]], + full_document: str = ..., + resume_after: Optional[str] = ..., + max_await_time_ms: Optional[int] = ..., + batch_size: Optional[int] = ..., + collation: Optional[Collation] = ..., + start_at_operation_time: Optional[Timestamp] = ..., + session: Optional[ClientSession] = ...) -> DatabaseChangeStream: ... + def command( + self, + command: Union[str, Mapping[str, Any]], + value: int = ..., + check: bool = ..., + allowable_errors: Optional[Sequence[str]] = ..., + read_preference: _ServerMode = ..., + codec_options: CodecOptions = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Any: ... + def list_collections(self, session: Optional[ClientSession] = ..., **kwargs: Any) -> CommandCursor: ... + def list_collection_names(self, session: Optional[ClientSession] = ...) -> List[str]: ... + def collection_names(self, include_system_collections: bool = ..., session: Optional[ClientSession] = ...) -> List[str]: ... + def drop_collection( + self, + name_or_collection: Union[str, Collection], + session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def validate_collection( + self, + name_or_collection: Union[str, Collection], + scandata: bool = ..., + full: bool = ..., + session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def current_op(self, include_all: bool = ..., session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def profiling_level(self, session: Optional[ClientSession] = ...) -> int: ... + def set_profiling_level(self, level: int, slow_ms: Optional[int] = ..., session: Optional[ClientSession] = ...) -> None: ... + def profiling_info(self, session: Optional[ClientSession] = ...) -> List[Any]: ... def error(self) -> Any: ... def last_status(self) -> Any: ... def previous_error(self) -> Any: ... def reset_error_history(self) -> None: ... def __iter__(self) -> 'Database': ... def __next__(self) -> None: ... - def _default_role(self, read_only: bool) -> str: ... - def _create_or_update_user(self, create: bool, name: str, password: str, read_only: bool, **kwargs: Any) -> None: ... - def _legacy_add_user(self, name: str, password: str, read_only: bool, **kwargs: Any) -> None: ... - def add_user(self, name: str, password: Optional[str] = ..., read_only: Optional[bool] = ..., **kwargs: Any) -> None: ... - def remove_user(self, name: str) -> None: ... - def authenticate(self, name: Optional[str] = ..., password: Optional[str] = ..., source: Optional[str] = ..., mechanism: str = ..., **kwargs: Any) -> bool: ... + def add_user( + self, + name: str, + password: Optional[str] = ..., + read_only: Optional[bool] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> None: ... + def remove_user(self, name: str, session: Optional[ClientSession] = ...) -> None: ... + def authenticate( + self, + name: Optional[str] = ..., + password: Optional[str] = ..., + source: Optional[str] = ..., + mechanism: str = ..., + **kwargs: Any) -> bool: ... def logout(self) -> None: ... - def dereference(self, dbref: DBRef, **kwargs: Any) -> Dict[str, Any]: ... + def dereference(self, dbref: DBRef, session: Optional[ClientSession] = ..., **kwargs: Any) -> Dict[str, Any]: ... def eval(self, code: str, *args: Any) -> Any: ... - def __call__(self, *args: Any, **kwargs: Any): ... class SystemJS(object): def __init__(self, database: Database) -> None: ... diff --git a/pymongo/driver_info.pyi b/pymongo/driver_info.pyi new file mode 100644 index 0000000000..351cfe955b --- /dev/null +++ b/pymongo/driver_info.pyi @@ -0,0 +1,4 @@ +from typing import Optional + +class DriverInfo: + def __new__(cls, name: Optional[str] = ..., version: Optional[str] = ..., platform: Optional[str] = ...) -> DriverInfo: ... diff --git a/pymongo/errors.pyi b/pymongo/errors.pyi index 427eb06082..59d27b2d28 100644 --- a/pymongo/errors.pyi +++ b/pymongo/errors.pyi @@ -1,18 +1,24 @@ -from bson.errors import InvalidDocument +from bson.errors import InvalidDocument as InvalidDocument -from typing import Any, Dict, Mapping, Optional +from typing import Any, Dict, Iterable, Mapping, Optional + +class PyMongoError(Exception): + def __init__(self, message: str = ..., error_labels: Optional[Iterable[str]] = ...) -> None: ... + def has_error_label(self, label: str) -> bool: ... -class PyMongoError(Exception): ... class ProtocolError(PyMongoError): ... class ConnectionFailure(PyMongoError): ... class AutoReconnect(ConnectionFailure): - def __init__(self, message: str = '', errors: Any = None) -> None: ... + def __init__(self, message: str = ..., errors: Any = ...) -> None: ... + details: Any + errors: Any + class NetworkTimeout(AutoReconnect): ... class NotMasterError(AutoReconnect): ... class ServerSelectionTimeoutError(AutoReconnect): ... class ConfigurationError(PyMongoError): ... class OperationFailure(PyMongoError): - def __init__(self, error: str, code: Optional[int] = None, details: Optional[Mapping[str, Any]] = None) -> None: ... + def __init__(self, error: str, code: Optional[int] = ..., details: Optional[Mapping[str, Any]] = ...) -> None: ... @property def code(self) -> int: ... @property diff --git a/pymongo/helpers.pyi b/pymongo/helpers.pyi deleted file mode 100644 index 46bdb66915..0000000000 --- a/pymongo/helpers.pyi +++ /dev/null @@ -1,21 +0,0 @@ -from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union - -from bson import CodecOptions -from pymongo.collection import Collection -from pymongo.database import Database -from pymongo.monitoring import _EventListeners -from pymongo.pool import SocketInfo -from pymongo.read_preferences import _ServerMode - - -_UUNDER: str = ... -_UNICODE_REPLACE_CODEC_OPTIONS: CodecOptions = ... -def _gen_index_name(keys: Sequence[Tuple[Any, Any]]) -> str: ... -def _index_list(key_or_list: Union[str, Sequence[Tuple[str, Union[int, str]]]], direction: Optional[Union[int, str]] = ...) -> List[Tuple[str, Union[int, str]]]: ... -def _index_document(index_list: Sequence[Tuple[str, Union[int, str]]]) -> Mapping[str, Any]: ... -def _unpack_response(response: bytes, cursor_id: Optional[int] = ..., codec_options: CodecOptions = ...) -> Dict[str, Any]: ... -def _check_command_response(response: bytes, msg: Optional[str] = ..., allowable_errors: Optional[Sequence[str]] = ..., parse_write_concern_error: bool = ...) -> None: ... -def _check_gle_response(response: bytes) -> Dict[str, Any]: ... -def _first_batch(sock_info: SocketInfo, db: Database, coll: Collection, query: Mapping[str, Any], ntoreturn: int, slave_ok: bool, codec_options: CodecOptions, read_preference: _ServerMode, cmd: Mapping[str, Any], listeners: _EventListeners) -> Dict[str, Any]: ... -def _check_write_command_response(results: Mapping[str, Any]) -> None: ... -def _fields_list_to_dict(fields: Sequence[str], option_name: str) -> Dict[str, int]: ... diff --git a/pymongo/ismaster.pyi b/pymongo/ismaster.pyi index 1be35fb708..7b4cee03c3 100644 --- a/pymongo/ismaster.pyi +++ b/pymongo/ismaster.pyi @@ -1,7 +1,6 @@ from typing import Any, Dict, List, Mapping, Optional, Tuple -def _get_server_type(doc: Mapping[str, Any]) -> int: ... class IsMaster(object): def __init__(self, doc: Mapping[str, Any]) -> None: ... @property diff --git a/pymongo/max_staleness_selectors.pyi b/pymongo/max_staleness_selectors.pyi index ea56715b6b..00493d80b2 100644 --- a/pymongo/max_staleness_selectors.pyi +++ b/pymongo/max_staleness_selectors.pyi @@ -3,7 +3,4 @@ from pymongo.server_selectors import Selection IDLE_WRITE_PERIOD: int = ... SMALLEST_MAX_STALENESS: int = ... -def _validate_max_staleness(max_staleness: int, heartbeat_frequency: int) -> None: ... -def _with_primary(max_staleness: int, selection: Selection) -> Selection: ... -def _no_primary(max_staleness: int, selection: Selection) -> Selection: ... def select(max_staleness: int, selection: Selection) -> Selection: ... diff --git a/pymongo/message.pyi b/pymongo/message.pyi index f7f263b62f..69f1227b30 100644 --- a/pymongo/message.pyi +++ b/pymongo/message.pyi @@ -12,40 +12,38 @@ from pymongo.read_preferences import _ServerMode MAX_INT32: int = ... MIN_INT32: int = ... -_COMMAND_OVERHEAD: int = ... -_INSERT: int = ... -_UPDATE: int = ... -_DELETE: int = ... -_EMPTY: bytes = ... -_BSONOBJ: bytes = ... -_ZERO_8: bytes = ... -_ZERO_16: bytes = ... -_ZERO_32: bytes = ... -_ZERO_64: bytes = ... -_SKIPLIM: bytes = ... -_OP_MAP: Dict[int, bytes] = ... -_UJOIN: str = ... -def _randint() -> int: ... -def _maybe_add_read_preference(spec: Mapping[str, Any], read_preference: _ServerMode) -> Dict[str, Any]: ... -def _convert_exception(exception: Exception) -> Dict[str, str]: ... -def _convert_write_result(operation: Union[_Query, _GetMore], command: Mapping[str, Any], result: Mapping[str, Any]) -> Dict[str, Any]: ... -_OPTIONS: Mapping[str, Any] = ... -_MODIFIERS: Mapping[str, Any] = ... -def _gen_explain_command(coll: Collection, spec: Mapping[str, Any], projection: Union[Mapping[str, bool], Sequence[str]], skip: int, limit: int, batch_size: int, options: bool, read_concern: ReadConcern) -> Dict[str, Any]: ... -def _gen_find_command(coll: Collection, spec: Mapping[str, Any], projection: Union[Mapping[str, bool], Sequence[str]], skip: int, limit: int, batch_size: int, options: bool, read_concern: ReadConcern = ..., collation: Optional[Collation] = ...) -> Dict[str, Any]: ... -def _gen_get_more_command(cursor_id: int, coll: Collection, batch_size: int, max_await_time_ms: int) -> Dict[str, Any]: ... class _Query(object): - def __init__(self, flags: bool, db: Database, coll: Collection, ntoskip: int, spec: Mapping[str, Any], fields: Union[Mapping[str, bool], Sequence[str]], codec_options: CodecOptions, read_preference: _ServerMode, limit: int, batch_size: int, read_concern: ReadConcern, collation: Collation) -> None: ... + def __init__( + self, + flags: bool, + db: Database, + coll: Collection, + ntoskip: int, + spec: Mapping[str, Any], + fields: Union[Mapping[str, bool], Sequence[str]], + codec_options: CodecOptions, + read_preference: _ServerMode, + limit: int, + batch_size: int, + read_concern: ReadConcern, + collation: Collation) -> None: ... def as_command(self) -> Dict[str, Any]: ... def get_message(self, set_slave_ok: bool, is_mongos: bool, use_cmd: bool = ...) -> Tuple[int, bytes, int]: ... class _GetMore(object): - def __init__(self, db: Database, coll: Collection, ntoreturn: int, cursor_id: int, codec_options: CodecOptions, max_await_time_ms: Optional[int] = ...) -> None: ... + def __init__( + self, + db: Database, + coll: Collection, + ntoreturn: int, + cursor_id: int, + codec_options: CodecOptions, + max_await_time_ms: Optional[int] = ...) -> None: ... def as_command(self) -> Mapping[str, Any]: ... def get_message(self, dummy0: Any, dummy1: Any, use_cmd: bool = ...) -> Tuple[Any]: ... -class _CursorAddress(tuple): +class _CursorAddress(Tuple[str, int]): def __new__(cls, address: Tuple[str, int], namespace: Any) -> '_CursorAddress': ... @property def namespace(self) -> Any: ... @@ -55,27 +53,62 @@ class _CursorAddress(tuple): def __last_error(namespace: str, args: Dict[str, Any]) -> Tuple[int, bytes, int]: ... def __pack_message(operation: Union[_Query, _GetMore], data: bytes) -> Tuple[int, bytes]: ... -def insert(collection_name: str, docs: Mapping[str, Any], check_keys: bool, safe: bool, last_error_args: Mapping[str, Any], continue_on_error: bool, opts: CodecOptions) -> Tuple[int, bytes, int]: ... -def update(collection_name: str, upsert: bool, multi: bool, spec: Mapping[str, Any], doc: Mapping[str, Any], safe: bool, last_error_args: Mapping[str, Any], check_keys: bool, opts: CodecOptions) -> Tuple[int, bytes, int]: ... -def query(options: int, collection_name: str, num_to_skip: int, num_to_return: int, query: Mapping[str, Any], field_selector: Mapping[str, Any], opts: CodecOptions, check_keys: bool = ...) -> Tuple[int, bytes, int]: ... +def insert( + collection_name: str, + docs: Mapping[str, Any], + check_keys: bool, + safe: bool, + last_error_args: Mapping[str, Any], + continue_on_error: bool, + opts: CodecOptions) -> Tuple[int, bytes, int]: ... +def update( + collection_name: str, + upsert: bool, + multi: bool, + spec: Mapping[str, Any], + doc: Mapping[str, Any], + safe: bool, + last_error_args: Mapping[str, Any], + check_keys: bool, + opts: CodecOptions) -> Tuple[int, bytes, int]: ... +def query( + options: int, + collection_name: str, + num_to_skip: int, + num_to_return: int, + query: Mapping[str, Any], + field_selector: Mapping[str, Any], + opts: CodecOptions, + check_keys: bool = ...) -> Tuple[int, bytes, int]: ... def get_more(collection_name: str, num_to_return: int, cursor_id: int) -> Tuple[int, bytes]: ... -def delete(collection_name: str, spec: Mapping[str, Any], safe: bool, last_error_args: Mapping[str, Any], opts: CodecOptions, flags: int = 0) -> Tuple[int, bytes, int]: ... +def delete( + collection_name: str, + spec: Mapping[str, Any], + safe: bool, + last_error_args: Mapping[str, Any], + opts: CodecOptions, flags: int = ...) -> Tuple[int, bytes, int]: ... def kill_cursors(cursor_ids: Sequence[int]) -> Tuple[int, bytes]: ... _FIELD_MAP: Dict[str, str] = ... class _BulkWriteContext(object): - def __init__(self, database_name: str, command: Mapping[str, Any], sock_info: SocketInfo, operation_id: int, listeners: _EventListeners) -> None: ... + def __init__( + self, + database_name: str, + command: Mapping[str, Any], + sock_info: SocketInfo, + operation_id: int, + listeners: _EventListeners) -> None: ... @property def max_bson_size(self) -> int: ... @property def max_message_size(self) -> int: ... @property def max_write_batch_size(self) -> int: ... - def legacy_write(self, request_id: int, msg: bytes, max_doc_size: int, acknowledged: bool, docs: Sequence[Mapping[str, Any]]) -> Dict[str, Any]: ... + def legacy_write( + self, + request_id: int, + msg: bytes, + max_doc_size: int, + acknowledged: bool, + docs: Sequence[Mapping[str, Any]]) -> Dict[str, Any]: ... def write_command(self, request_id: int, msg: bytes, docs: Sequence[Mapping[str, Any]]) -> Dict[str, Any]: ... - def _start(self, request_id: int, docs: Sequence[Mapping[str, Any]]) -> Dict[str, Any]: ... - def _succeed(self, request_id: int, reply: Mapping[str, Any], duration: datetime.timedelta) -> None: ... - def _fail(self, request_id: int, failure: Mapping[str, Any], duration: datetime.timedelta) -> None: ... -def _raise_document_too_large(operation: str, doc_size: int, max_size: int) -> None: ... -def _do_batched_insert(collection_name: str, docs: Sequence[Mapping[str, Any]], check_keys: bool, safe: bool, last_error_args: Mapping[str, Any], continue_on_error: bool, opts: CodecOptions, ctx: _BulkWriteContext) -> None: ... -def _do_batched_write_command(namespace: str, operation: int, command: Mapping[str, Any], docs: Sequence[Mapping[str, Any]], check_keys: bool, opts: CodecOptions, ctx: _BulkWriteContext) -> None: ... diff --git a/pymongo/mongo_client.pyi b/pymongo/mongo_client.pyi index e2437383e9..dbd9d7bef2 100644 --- a/pymongo/mongo_client.pyi +++ b/pymongo/mongo_client.pyi @@ -20,13 +20,13 @@ from pymongo.server import Server class MongoClient(BaseObject): HOST: str = ... PORT: int = ... - def __init__(self, host: str = ..., port: int = ..., document_class: Type[Any] = ..., tz_aware: Optional[bool] = ..., connect: Optional[bool] = ..., **kwargs: Any) -> None: ... - def _cache_credentials(self, source: str, credentials: MongoCredential, connect: bool = ...) -> None: ... - def _purge_credentials(self, source: str) -> None: ... - def _cached(self, dbname: str, coll: str, index: Union[str, int]) -> bool: ... - def _cache_index(self, dbname: str, collection: str, index: Union[str, int], cache_for: int) -> None: ... - def _purge_index(self, database_name: str, collection_name: Optional[str] = ..., index_name: Optional[str] = ...) -> None: ... - def _server_property(self, attr_name: str) -> Any: ... + def __init__( + self, + host: str = ..., + port: int = ..., + document_class: Type[Any] = ..., + tz_aware: Optional[bool] = ..., + connect: Optional[bool] = ..., **kwargs: Any) -> None: ... @property def event_listeners(self) -> _EventListeners: ... @property @@ -60,36 +60,27 @@ class MongoClient(BaseObject): @property def server_selection_timeout(self) -> int: ... @property - def _is_writable(self) -> bool: ... def close(self) -> None: ... def set_cursor_manager(self, manager_class: CursorManager) -> None: ... - def _get_topology(self) -> Topology: ... - @contextlib.contextmanager - def _get_socket(self, selector: Callable[[Sequence[Server]], Sequence[Server]]) -> None: ... - def _socket_for_writes(self) -> SocketInfo: ... - @contextlib.contextmanager - def _socket_for_reads(self, read_preference: _ServerMode) -> Tuple[SocketInfo, bool]: ... - def _send_message_with_response(self, operation: Union[_Query, _GetMore], read_preference: Optional[_ServerMode] = ..., exhaust: bool = ..., address: Optional[Tuple[str, int]] = ...) -> Response: ... - def _reset_on_error(self, server: Server, func: Callable[[Any], Any], *args: Any, **kwargs: Any) -> Any: ... def __reset_server(self, address: Tuple[str, int]) -> None: ... - def _reset_server_and_request_check(self, address: Tuple[str, int]) -> None: ... def __eq__(self, other: Any) -> bool: ... def __ne__(self, other: Any) -> bool: ... - def _repr_helper(self) -> str: ... def __repr__(self) -> str: ... def __getattr__(self, name: str) -> Database: ... def __getitem__(self, name: str) -> Database: ... def close_cursor(self, cursor_id: int, address: Optional[Tuple[str, int]] = ...) -> None: ... - def _close_cursor_now(self, cursor_id: int, address: Optional[Tuple[str, int]] = ...) -> None: ... def kill_cursors(self, cursor_ids: Sequence[int], address: Optional[Tuple[str, int]] = ...) -> None: ... - def _kill_cursors(self, cursor_ids: Sequence[int], address: Union[Tuple[str, int], _CursorAddress], topology: Topology) -> None: ... - def _process_periodic_tasks(self) -> None: ... def server_info(self) -> Dict[str, Any]: ... def database_names(self) -> List[str]: ... def drop_database(self, name_or_database: Union[str, Database]) -> None: ... def get_default_database(self) -> Database: ... - def get_database(self, name: Optional[str] = ..., codec_options: Optional[CodecOptions] = ..., read_preference: Optional[_ServerMode] = ..., write_concern: Optional[WriteConcern] = ..., read_concern: Optional[ReadConcern] = ...) -> Database: ... - def _database_default_options(self, name: str) -> Database: ... + def get_database( + self, + name: Optional[str] = ..., + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ...) -> Database: ... @property def is_locked(self) -> bool: ... def fsync(self, **kwargs: Any) -> Dict[str, Any]: ... diff --git a/pymongo/monitor.pyi b/pymongo/monitor.pyi index ba05b0b23c..be8fabe66e 100644 --- a/pymongo/monitor.pyi +++ b/pymongo/monitor.pyi @@ -8,12 +8,13 @@ from pymongo.topology import Topology class Monitor(object): - def __init__(self, server_description: ServerDescription, topology: Topology, pool: Pool, topology_settings: TopologySettings) -> None: ... + def __init__( + self, + server_description: ServerDescription, + topology: Topology, + pool: Pool, + topology_settings: TopologySettings) -> None: ... def open(self) -> None: ... def close(self) -> None: ... - def join(self, timeout: int = None) -> None: ... + def join(self, timeout: Optional[int] = ...) -> None: ... def request_check(self) -> None: ... - def _run(self) -> None: ... - def _check_with_retry(self) -> ServerDescription: ... - def _check_once(self, metadata: Optional[Any] = None) -> ServerDescription: ... - def _check_with_socket(self, sock_info: SocketInfo, metadata: Optional[Any] = None) -> Tuple[IsMaster, int]: ... diff --git a/pymongo/monitoring.pyi b/pymongo/monitoring.pyi index b5d18f6b6b..75b8bce2ab 100644 --- a/pymongo/monitoring.pyi +++ b/pymongo/monitoring.pyi @@ -6,13 +6,12 @@ from pymongo.ismaster import IsMaster from pymongo.server_description import ServerDescription -class _Listeners(NamedTuple): - command_listeners: Sequence[CommandListener] - server_listeners: Sequence[ServerListener] - server_heartbeat_listeners: Sequence[ServerHeartbeatListener] - topology_listeners: Sequence[TopologyListener] - -_LISTENERS: _Listeners = ... +_Listeners = NamedTuple('_Listeners', [ + ('command_listeners', Sequence[CommandListener]), + ('server_listeners', Sequence[ServerListener]), + ('server_heartbeat_listeners', Sequence[ServerHeartbeatListener]), + ('topology_listeners', Sequence[TopologyListener]), +]) class _EventListener(object): ... @@ -27,19 +26,16 @@ class ServerHeartbeatListener(_EventListener): def failed(self, event: ServerHeartbeatFailedEvent) -> None: ... class TopologyListener(_EventListener): - def opened(self, event: TopologyOpenedEvent) -> None: ... - def description_changed(self, event: TopologyDescriptionChangedEvent) -> None: ... - def closed(self, event: TopologyClosedEvent) -> None: ... + def opened(self, event: _ServerEvent) -> None: ... + def description_changed(self, event: _ServerEvent) -> None: ... + def closed(self, event: _ServerEvent) -> None: ... class ServerListener(_EventListener): - def opened(self, event: ServerOpeningEvent) -> None: ... - def description_changed(self, event: ServerDescriptionChangedEvent) -> None: ... - def closed(self, event: ServerClosedEvent) -> None: ... + def opened(self, event: _ServerEvent) -> None: ... + def description_changed(self, event: _ServerEvent) -> None: ... + def closed(self, event: _ServerEvent) -> None: ... -def _to_micros(dur: datetime.timedelta) -> int: ... -def _validate_event_listeners(option: str, listeners: Sequence[_EventListener]) -> Sequence[_EventListener]: ... def register(listener: _EventListener) -> None: ... -_SENSITIVE_COMMANDS: Set[str] = ... class _CommandEvent(object): def __init__(self, command_name: str, request_id: int, connection_id: Tuple[str, int], operation_id: int) -> None: ... @@ -60,7 +56,14 @@ class CommandStartedEvent(_CommandEvent): def database_name(self) -> str: ... class CommandSucceededEvent(_CommandEvent): - def __init__(self, duration: datetime.timedelta, reply: Mapping[str, Any], command_name: str, request_id: int, connection_id: Tuple[str, int], operation_id: int) -> None: ... + def __init__( + self, + duration: datetime.timedelta, + reply: Mapping[str, Any], + command_name: str, + request_id: int, + connection_id: Tuple[str, int], + operation_id: int) -> None: ... @property def duration_micros(self) -> int: ... @property @@ -140,15 +143,52 @@ class _EventListeners(object): @property def enabled_for_topology(self) -> bool: ... def event_listeners(self) -> Tuple[Sequence[Any]]: ... - def publish_command_start(self, command: Mapping[str, Any], database_name: str, request_id: int, connection_id: Tuple[str, int], op_id: Optional[int] = ...) -> None: ... - def publish_command_success(self, duration: datetime.timedelta, reply: Mapping[str, Any], command_name: str, request_id: int, connection_id: Tuple[str, int], op_id: Optional[int] = ...) -> None: ... - def publish_command_failure(self, duration: datetime.timedelta, failure: Mapping[str, Any], command_name: str, request_id: int, connection_id: Tuple[str, int], op_id: Optional[int] = ...) -> None: ... + def publish_command_start( + self, + command: Mapping[str, Any], + database_name: str, + request_id: int, + connection_id: Tuple[str, int], + op_id: Optional[int] = ...) -> None: ... + def publish_command_success( + self, + duration: datetime.timedelta, + reply: Mapping[str, Any], + command_name: str, + request_id: int, + connection_id: Tuple[str, int], + op_id: Optional[int] = ...) -> None: ... + def publish_command_failure( + self, + duration: datetime.timedelta, + failure: Mapping[str, Any], + command_name: str, + request_id: int, + connection_id: Tuple[str, int], + op_id: Optional[int] = ...) -> None: ... def publish_server_heartbeat_started(self, connection_id: Tuple[str, int]) -> None: ... - def publish_server_heartbeat_succeeded(self, connection_id: Tuple[str, int], duration: int, reply: Union[Mapping[str, Any], Exception]) -> None: ... - def publish_server_heartbeat_failed(self, connection_id: Tuple[str, int], duration: int, reply: Union[Mapping[str, Any], Exception]) -> None: ... + def publish_server_heartbeat_succeeded( + self, + connection_id: Tuple[str, int], + duration: int, + reply: Union[Mapping[str, Any], Exception]) -> None: ... + def publish_server_heartbeat_failed( + self, + connection_id: Tuple[str, int], + duration: int, + reply: Union[Mapping[str, Any], Exception]) -> None: ... def publish_server_opened(self, server_address: Tuple[str, int], topology_id: int) -> None: ... def publish_server_closed(self, server_address: Tuple[str, int], topology_id: int) -> None: ... - def publish_server_description_changed(self, previous_description: ServerDescription, new_description: ServerDescription, server_address: Tuple[str, int], topology_id: int) -> None: ... + def publish_server_description_changed( + self, + previous_description: ServerDescription, + new_description: ServerDescription, + server_address: Tuple[str, int], + topology_id: int) -> None: ... def publish_topology_opened(self, topology_id: int) -> None: ... def publish_topology_closed(self, topology_id: int) -> None: ... - def publish_topology_description_changed(self, previous_description: ServerDescription, new_description: ServerDescription, topology_id: int) -> None: ... + def publish_topology_description_changed( + self, + previous_description: ServerDescription, + new_description: ServerDescription, + topology_id: int) -> None: ... diff --git a/pymongo/monotonic.pyi b/pymongo/monotonic.pyi new file mode 100644 index 0000000000..f0bb23fff8 --- /dev/null +++ b/pymongo/monotonic.pyi @@ -0,0 +1 @@ +def time() -> float: ... diff --git a/pymongo/network.pyi b/pymongo/network.pyi index 18b1d8142b..5c6643659d 100644 --- a/pymongo/network.pyi +++ b/pymongo/network.pyi @@ -8,10 +8,24 @@ from pymongo.read_concern import ReadConcern from pymongo.read_preferences import _ServerMode -def command(sock: socket, dbname: str, spec: Mapping[str, Any], slave_ok: bool, is_mongos: bool, read_preference: _ServerMode, codec_options: CodecOptions, check: bool = ..., allowable_errors: Optional[Sequence[str]] = ..., address: Optional[Tuple[str, int]] = ..., check_keys: bool = ..., listeners: Optional[_EventListeners] = ..., max_bson_size: Optional[int] = ..., read_concern: ReadConcern = ..., parse_write_concern_error: bool = ..., collation: Optional[Collation] = ...) -> Dict[str, Any]: ... +def command( + sock: socket, + dbname: str, + spec: Mapping[str, Any], + slave_ok: bool, + is_mongos: bool, + read_preference: _ServerMode, + codec_options: CodecOptions, + check: bool = ..., + allowable_errors: Optional[Sequence[str]] = ..., + address: Optional[Tuple[str, int]] = ..., + check_keys: bool = ..., + listeners: Optional[_EventListeners] = ..., + max_bson_size: Optional[int] = ..., + read_concern: ReadConcern = ..., + parse_write_concern_error: bool = ..., + collation: Optional[Collation] = ...) -> Dict[str, Any]: ... def receive_message(sock: socket, operation: int, request_id: int, max_message_size: int = ...) -> bytes: ... -def _receive_data_on_socket(sock: socket, length: int) -> bytes: ... -def _errno_from_exception(exc: Exception) -> Union[int, str, None]: ... class SocketChecker(object): def __init__(self) -> None: ... diff --git a/pymongo/operations.pyi b/pymongo/operations.pyi index f42bcc0b91..25df024990 100644 --- a/pymongo/operations.pyi +++ b/pymongo/operations.pyi @@ -1,42 +1,55 @@ -from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union - -from pymongo.bulk import _Bulk - +from pymongo.collation import Collation +from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union class _WriteOp(object): - def __init__(self, filter: Optional[Mapping[str, Any]] = None, doc: Optional[Mapping[str, Any]] = None, upsert: Optional[bool] = None) -> None: ... + def __init__( + self, + filter: Optional[Mapping[str, Any]] = ..., + doc: Optional[Mapping[str, Any]] = ..., + upsert: Optional[bool] = ...) -> None: ... def __eq__(self, other: Any) -> bool: ... def __ne__(self, other: Any) -> bool: ... class InsertOne(_WriteOp): def __init__(self, document: Mapping[str, Any]) -> None: ... - def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... def __repr__(self) -> str: ... class DeleteOne(_WriteOp): - def __init__(self, filter: Mapping[str, Any]) -> None: ... - def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... + def __init__(self, filter: Mapping[str, Any], collation: Optional[Collation] = ...) -> None: ... def __repr__(self) -> str: ... class DeleteMany(_WriteOp): - def __init__(self, filter: Mapping[str, Any]) -> None: ... - def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... + def __init__(self, filter: Mapping[str, Any], collation: Optional[Collation] = ...) -> None: ... def __repr__(self) -> str: ... class ReplaceOne(_WriteOp): - def __init__(self, filter: Mapping[str, Any], replacement: Mapping[str, Any], upsert: bool = False) -> None: ... - def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... + def __init__( + self, + filter: Mapping[str, Any], + replacement: Mapping[str, Any], + upsert: bool = ..., + collation: Optional[Collation] = ...) -> None: ... def __repr__(self) -> str: ... class UpdateOne(_WriteOp): - def __init__(self, filter: Mapping[str, Any], update: Mapping[str, Any], upsert: bool = False) -> None: ... - def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... - def __repr__(self) -> None: ... + def __init__( + self, + filter: Mapping[str, Any], + update: Mapping[str, Any], + upsert: bool = ..., + collation: Optional[Collation] = ..., + array_filters: Optional[List[Mapping[str, Any]]] = ...) -> None: ... + def __repr__(self) -> str: ... class UpdateMany(_WriteOp): - def __init__(self, filter: Mapping[str, Any], update: Mapping[str, Any], upsert: bool = False) -> None: ... - def _add_to_bulk(self, bulkobj: _Bulk) -> None: ... - def __repr__(self) -> None: ... + def __init__( + self, + filter: Mapping[str, Any], + update: Mapping[str, Any], + upsert: bool = ..., + collation: Optional[Collation] = ..., + array_filters: Optional[List[Mapping[str, Any]]] = ...) -> None: ... + def __repr__(self) -> str: ... class IndexModel(object): def __init__(self, keys: Union[str, Sequence[Tuple[str, Union[int, str]]]], **kwargs: Any) -> None: ... diff --git a/pymongo/periodic_executor.pyi b/pymongo/periodic_executor.pyi index e715301b28..f95eee3198 100644 --- a/pymongo/periodic_executor.pyi +++ b/pymongo/periodic_executor.pyi @@ -3,14 +3,8 @@ from typing import Any, Callable, Optional class PeriodicExecutor(object): - def __init__(self, interval: int, min_interval: int, target: Callable[..., Any], name: Optional[str] = None) -> None: ... + def __init__(self, interval: int, min_interval: int, target: Callable[..., Any], name: Optional[str] = ...) -> None: ... def open(self) -> None: ... - def close(self, dummy: Optional[Any] = None) -> None: ... - def join(self, timeout: int = None) -> None: ... + def close(self, dummy: Optional[Any] = ...) -> None: ... + def join(self, timeout: Optional[int] = ...) -> None: ... def wake(self) -> None: ... - def __should_stop(self) -> bool: ... - def _run(self) -> None: ... - -def _register_executor(executor: PeriodicExecutor) -> None: ... -def _on_executor_deleted(ref: weakref.ref) -> None: ... -def _shutdown_executors() -> None: ... diff --git a/pymongo/pool.pyi b/pymongo/pool.pyi index f8bd76f3fc..d3ee3ff785 100644 --- a/pymongo/pool.pyi +++ b/pymongo/pool.pyi @@ -1,11 +1,13 @@ import contextlib from socket import socket from ssl import SSLContext -from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union +from typing import Any, Dict, Iterator, Mapping, Optional, Sequence, Tuple, Union from bson.codec_options import CodecOptions from pymongo.auth import MongoCredential from pymongo.collation import Collation +from pymongo.compression_support import CompressionSettings +from pymongo.driver_info import DriverInfo from pymongo.ismaster import IsMaster from pymongo.monitoring import _EventListeners from pymongo.read_concern import ReadConcern @@ -13,9 +15,23 @@ from pymongo.read_preferences import _ServerMode from pymongo.write_concern import WriteConcern -def _raise_connection_failure(address: Tuple[str, int], error: Exception) -> None: ... class PoolOptions(object): - def __init__(self, max_pool_size: int = ..., min_pool_size: int = ..., max_idle_time_ms: Optional[int] = ..., connect_timeout: Optional[int] = ..., socket_timeout: Optional[int] = ..., wait_queue_timeout: Optional[int] = ..., wait_queue_multiple: Optional[int] = ..., ssl_context: Union[SSLContext, None] = ..., ssl_match_hostname: bool = ..., socket_keepalive: bool = ..., event_listeners: Optional[_EventListeners] = ..., appname: Optional[str] = ...) -> None: ... + def __init__( + self, + max_pool_size: int = ..., + min_pool_size: int = ..., + max_idle_time_ms: Optional[int] = ..., + connect_timeout: Optional[int] = ..., + socket_timeout: Optional[int] = ..., + wait_queue_timeout: Optional[int] = ..., + wait_queue_multiple: Optional[int] = ..., + ssl_context: Union[SSLContext, None] = ..., + ssl_match_hostname: bool = ..., + socket_keepalive: bool = ..., + event_listeners: Optional[_EventListeners] = ..., + appname: Optional[str] = ..., + driver: Optional[DriverInfo] = ..., + compression_settings: Optional[CompressionSettings] = ...) -> None: ... @property def max_pool_size(self) -> int: ... @property @@ -42,10 +58,27 @@ class PoolOptions(object): def appname(self) -> str: ... @property def metadata(self) -> Dict[str, Any]: ... + @property + def driver(self) -> DriverInfo: ... + @property + def compression_settings(self) -> CompressionSettings: ... class SocketInfo(object): def __init__(self, sock: socket, pool: Pool, ismaster: IsMaster, address: Tuple[str, int]) -> None: ... - def command(self, dbname: str, spec: Mapping[str, Any], slave_ok: bool = ..., read_preference: _ServerMode = ..., codec_options: CodecOptions = ..., check: bool = ..., allowable_errors: Optional[Sequence[str]] = ..., check_keys: bool = ..., read_concern: ReadConcern = ..., write_concern: Optional[WriteConcern] = ..., parse_write_concern_error: bool = ..., collation: Optional[Collation] = ...) -> Dict[str, MongoCredential]: ... + def command( + self, + dbname: str, + spec: Mapping[str, Any], + slave_ok: bool = ..., + read_preference: _ServerMode = ..., + codec_options: CodecOptions = ..., + check: bool = ..., + allowable_errors: Optional[Sequence[str]] = ..., + check_keys: bool = ..., + read_concern: ReadConcern = ..., + write_concern: Optional[WriteConcern] = ..., + parse_write_concern_error: bool = ..., + collation: Optional[Collation] = ...) -> Dict[str, MongoCredential]: ... def send_message(self, message: bytes, max_doc_size: int) -> None: ... def receive_message(self, operation: bytes, request_id: int) -> bytes: ... def legacy_write(self, request_id: int, msg: bytes, max_doc_size: int, with_last_error: bool) -> Dict[str, Any]: ... @@ -53,24 +86,17 @@ class SocketInfo(object): def check_auth(self, all_credentials: Mapping[str, MongoCredential]) -> None: ... def authenticate(self, credentials: MongoCredential) -> None: ... def close(self) -> None: ... - def _raise_connection_failure(self, error: Exception) -> None: ... def __eq__(self, other: Any) -> bool: ... def __ne__(self, other: Any) -> bool: ... def __hash__(self) -> int: ... def __repr__(self) -> str: ... -def _create_connection(address: Tuple[str, int], options: PoolOptions) -> socket: ... -def _configured_socket(address: Tuple[str, int], options: PoolOptions) -> socket: ... - class Pool: def __init__(self, address: Tuple[str, int], options: PoolOptions, handshake: bool = ...) -> None: ... def reset(self) -> None: ... def remove_stale_sockets(self) -> None: ... def connect(self) -> SocketInfo: ... @contextlib.contextmanager - def get_socket(self, all_credentials: Mapping[str, MongoCredential], checkout: bool = ...) -> SocketInfo: ... - def _get_socket_no_auth(self) -> SocketInfo: ... + def get_socket(self, all_credentials: Mapping[str, MongoCredential], checkout: bool = ...) -> Iterator[SocketInfo]: ... def return_socket(self, sock_info: SocketInfo) -> None: ... - def _check(self, sock_info: SocketInfo) -> SocketInfo: ... - def _raise_wait_queue_timeout(self) -> None: ... def __del__(self) -> None: ... diff --git a/pymongo/py.typed b/pymongo/py.typed new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pymongo/read_concern.pyi b/pymongo/read_concern.pyi index 2ce65e0181..d213ad4326 100644 --- a/pymongo/read_concern.pyi +++ b/pymongo/read_concern.pyi @@ -2,7 +2,7 @@ from typing import Any, Dict, Optional class ReadConcern(object): - def __init__(self, level: Optional[str] = None) -> None: ... + def __init__(self, level: Optional[str] = ...) -> None: ... @property def level(self) -> str: ... @property diff --git a/pymongo/read_preferences.pyi b/pymongo/read_preferences.pyi index 869bef60a7..00c91b4a44 100644 --- a/pymongo/read_preferences.pyi +++ b/pymongo/read_preferences.pyi @@ -9,12 +9,9 @@ _SECONDARY: int = ... _SECONDARY_PREFERRED: int = ... _NEAREST: int = ... _MONGOS_MODES: Tuple[str, ...] = ... -def _validate_tag_sets(tag_sets: Union[Sequence[Mapping[str, Any]], None]) -> Optional[List[Mapping[str, Any]]]: ... -def _invalid_max_staleness_msg(max_staleness: int) -> str: ... -def _validate_max_staleness(max_staleness: int) -> int: ... class _ServerMode(object): - def __init__(self, mode: int, tag_sets: Optional[Sequence[Mapping[str, Any]]] = None, max_staleness: int = -1) -> None: ... + def __init__(self, mode: int, tag_sets: Optional[Sequence[Mapping[str, Any]]] = ..., max_staleness: int = ...) -> None: ... @property def name(self) -> str: ... @property @@ -40,23 +37,23 @@ class Primary(_ServerMode): def __eq__(self, other: Any) -> bool: ... class PrimaryPreferred(_ServerMode): - def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = None, max_staleness: int = -1) -> None: ... + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = ..., max_staleness: int = ...) -> None: ... def __call__(self, selection: Selection) -> Union[List[ServerDescription], Selection]: ... class Secondary(_ServerMode): - def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = None, - max_staleness: int = -1) -> None: ... + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = ..., + max_staleness: int = ...) -> None: ... def __call__(self, selection: Selection) -> Selection: ... class SecondaryPreferred(_ServerMode): - def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = None, max_staleness: int = -1) -> None: ... + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = ..., max_staleness: int = ...) -> None: ... def __call__(self, selection: Selection) -> Union[List[ServerDescription], Selection]: ... class Nearest(_ServerMode): - def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = None, max_staleness: int = -1) -> None: ... + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = ..., max_staleness: int = ...) -> None: ... def __call__(self, selection: Selection) -> Selection: ... -def make_read_preference(mode: int, tag_sets: Sequence[Mapping[str, Any]], max_staleness: int = -1) -> _ServerMode: ... +def make_read_preference(mode: int, tag_sets: Sequence[Mapping[str, Any]], max_staleness: int = ...) -> _ServerMode: ... _MODES: Tuple[str, ...] = ... class ReadPreference(object): diff --git a/pymongo/response.pyi b/pymongo/response.pyi index 6318b3232d..4b9a30945b 100644 --- a/pymongo/response.pyi +++ b/pymongo/response.pyi @@ -5,7 +5,13 @@ from typing import Tuple from pymongo.pool import Pool, SocketInfo class Response(object): - def __init__(self, data: bytes, address: Tuple[str, int], request_id: int, duration: datetime.timedelta, from_command: bool) -> None: ... + def __init__( + self, + data: bytes, + address: Tuple[str, int], + request_id: int, + duration: datetime.timedelta, + from_command: bool) -> None: ... @property def data(self) -> bytes: ... @property @@ -18,7 +24,15 @@ class Response(object): def from_command(self) -> bool: ... class ExhaustResponse(Response): - def __init__(self, data: bytes, address: Tuple[str, int], socket_info: SocketInfo, pool: Pool, request_id: int, duration: datetime.timedelta, from_command: bool) -> None: ... + def __init__( + self, + data: bytes, + address: Tuple[str, int], + socket_info: SocketInfo, + pool: Pool, + request_id: int, + duration: datetime.timedelta, + from_command: bool) -> None: ... @property def socket_info(self) -> SocketInfo: ... @property diff --git a/pymongo/results.pyi b/pymongo/results.pyi index 504e0efbc2..4e0015354b 100644 --- a/pymongo/results.pyi +++ b/pymongo/results.pyi @@ -3,7 +3,6 @@ from typing import Any, Dict, List, Mapping, Sequence class _WriteResult(object): def __init__(self, acknowledged: bool) -> None: ... - def _raise_if_unacknowledged(self, property_name: str) -> None: ... @property def acknowledged(self) -> bool: ... diff --git a/pymongo/saslprep.pyi b/pymongo/saslprep.pyi new file mode 100644 index 0000000000..b09e563c98 --- /dev/null +++ b/pymongo/saslprep.pyi @@ -0,0 +1,3 @@ +from typing import Text + +def saslprep(data: Text) -> Text: ... diff --git a/pymongo/server.pyi b/pymongo/server.pyi index 09eab3d796..14c6232135 100644 --- a/pymongo/server.pyi +++ b/pymongo/server.pyi @@ -1,7 +1,12 @@ import contextlib +import sys -from queue import Queue -from typing import Iterator, Mapping, Optional, Tuple, Union +import sys +if sys.version_info >= (3,): + from queue import Queue +else: + from Queue import Queue +from typing import Any, Callable, Iterator, Mapping, Optional, Sequence, Tuple, Union from bson import ObjectId from pymongo.auth import MongoCredential @@ -14,20 +19,32 @@ from pymongo.server_description import ServerDescription class Server(object): - def __init__(self, server_description: ServerDescription, pool: Pool, monitor: Monitor, topology_id: Optional[ObjectId] = None, listeners: Optional[_EventListeners] = None, events: Optional[Queue] = None) -> None: ... + def __init__( + self, + server_description: ServerDescription, + pool: Pool, + monitor: Monitor, + topology_id: Optional[ObjectId] = ..., + listeners: Optional[_EventListeners] = ..., + events: Optional[Queue[Tuple[Callable[..., Any], Sequence[Any]]]] = ...) -> None: ... def open(self) -> None: ... def reset(self) -> None: ... def close(self) -> None: ... def request_check(self) -> None: ... def send_message(self, message: Tuple[int, bytes], all_credentials: Mapping[str, MongoCredential]) -> None: ... - def send_message_with_response(self, operation: Union[_Query, _GetMore], set_slave_okay: bool, all_credentials: Mapping[str, MongoCredential], listeners: _EventListeners, exhaust: bool = False) -> Response: ... + def send_message_with_response( + self, + operation: Union[_Query, _GetMore], + set_slave_okay: bool, + all_credentials: Mapping[str, MongoCredential], + listeners: _EventListeners, + exhaust: bool = ...) -> Response: ... @contextlib.contextmanager - def get_socket(self, all_credentials: Mapping[str, MongoCredential], checkout: bool = False) -> Iterator[SocketInfo]: ... + def get_socket(self, all_credentials: Mapping[str, MongoCredential], checkout: bool = ...) -> Iterator[SocketInfo]: ... @property def description(self) -> ServerDescription: ... @description.setter def description(self, server_description: ServerDescription) -> None: ... @property def pool(self) -> Pool: ... - def _split_message(self, message: Union[Tuple[int, bytes, int], Tuple[int, bytes]]) -> Tuple[int, bytes, int]: ... def __str__(self) -> str: ... diff --git a/pymongo/server_description.pyi b/pymongo/server_description.pyi index 27c38d622d..e071cbc657 100644 --- a/pymongo/server_description.pyi +++ b/pymongo/server_description.pyi @@ -2,12 +2,16 @@ import datetime from typing import Any, Dict, Optional, Set, Tuple from pymongo.ismaster import IsMaster +from pymongo.server_type import SERVER_TYPE as SERVER_TYPE -def _total_seconds(delta: datetime.timedelta) -> float: ... - class ServerDescription(object): - def __init__(self, address: Tuple[str, int], ismaster: Optional[IsMaster] = ..., round_trip_time: Optional[float] = ..., error: Optional[Any] = ...) -> None: ... + def __init__( + self, + address: Tuple[str, int], + ismaster: Optional[IsMaster] = ..., + round_trip_time: Optional[float] = ..., + error: Optional[Any] = ...) -> None: ... @property def address(self) -> Tuple[str, int]: ... @property diff --git a/pymongo/server_selectors.pyi b/pymongo/server_selectors.pyi index 6e7eff48fd..eaaaac5f7a 100644 --- a/pymongo/server_selectors.pyi +++ b/pymongo/server_selectors.pyi @@ -7,7 +7,12 @@ from pymongo.topology_description import TopologyDescription class Selection(object): @classmethod def from_topology_description(cls: type, topology_description: TopologyDescription) -> 'Selection': ... - def __init__(self, topology_description: TopologyDescription, server_descriptions: Sequence[ServerDescription], common_wire_version: int, primary: ServerDescription) -> None: ... + def __init__( + self, + topology_description: TopologyDescription, + server_descriptions: Sequence[ServerDescription], + common_wire_version: int, + primary: ServerDescription) -> None: ... def with_server_descriptions(self, server_descriptions: Sequence[ServerDescription]) -> 'Selection': ... def secondary_with_max_last_write_date(self) -> ServerDescription: ... @property diff --git a/pymongo/server_type.pyi b/pymongo/server_type.pyi index 4788aa66c2..90534598c5 100644 --- a/pymongo/server_type.pyi +++ b/pymongo/server_type.pyi @@ -1,13 +1,14 @@ from typing import NamedTuple -class ServerType(NamedTuple): - Unknown: int - Mongos: int - RSPrimary: int - RSSecondary: int - RSArbiter: int - RSOther: int - RSGhost: int - Standalone: int +ServerType = NamedTuple('ServerType', [ + ('Unknown', int), + ('Mongos', int), + ('RSPrimary', int), + ('RSSecondary', int), + ('RSArbiter', int), + ('RSOther', int), + ('RSGhost', int), + ('Standalone', int), +]) SERVER_TYPE: ServerType = ... diff --git a/pymongo/settings.pyi b/pymongo/settings.pyi index 757e96b15d..42e7eb9cbb 100644 --- a/pymongo/settings.pyi +++ b/pymongo/settings.pyi @@ -7,7 +7,17 @@ from pymongo.server_description import ServerDescription class TopologySettings(object): - def __init__(self, seeds: Optional[Sequence[Tuple[str, int]]] = ..., replica_set_name: Optional[str] = ..., pool_class: Optional[Pool] = ..., pool_options: Optional[PoolOptions] = ..., monitor_class: Optional[Monitor] = ..., condition_class: Optional[threading.Condition] = ..., local_threshold_ms: int = ..., server_selection_timeout: int = ..., heartbeat_frequency: int = ...) -> None: ... + def __init__( + self, + seeds: Optional[Sequence[Tuple[str, int]]] = ..., + replica_set_name: Optional[str] = ..., + pool_class: Optional[Pool] = ..., + pool_options: Optional[PoolOptions] = ..., + monitor_class: Optional[Monitor] = ..., + condition_class: Optional[threading.Condition] = ..., + local_threshold_ms: int = ..., + server_selection_timeout: int = ..., + heartbeat_frequency: int = ...) -> None: ... @property def seeds(self) -> List[Tuple[str, int]]: ... @property diff --git a/pymongo/ssl_context.pyi b/pymongo/ssl_context.pyi index bafd0eff8e..33f4a663c1 100644 --- a/pymongo/ssl_context.pyi +++ b/pymongo/ssl_context.pyi @@ -15,4 +15,10 @@ class SSLContext(object): def __set_verify_mode(self, value: int) -> None: ... def load_cert_chain(self, certfile: str, keyfile: Optional[str] = ...) -> None: ... def load_verify_locations(self, cafile: Optional[str] = ..., dummy: Optional[Any] = ...) -> None: ... - def wrap_socket(self, sock: socket, server_side: bool = ..., do_handshake_on_connect: bool = ..., suppress_ragged_eofs: bool = ..., dummy: Optional[Any] = ...) -> ssl.SSLSocket: ... + def wrap_socket( + self, + sock: socket, + server_side: bool = ..., + do_handshake_on_connect: bool = ..., + suppress_ragged_eofs: bool = ..., + dummy: Optional[Any] = ...) -> ssl.SSLSocket: ... diff --git a/pymongo/ssl_match_hostname.pyi b/pymongo/ssl_match_hostname.pyi index 6b99fa2ffc..0bf9527f43 100644 --- a/pymongo/ssl_match_hostname.pyi +++ b/pymongo/ssl_match_hostname.pyi @@ -1,6 +1,4 @@ from typing import Any, Mapping, Match, Union class CertificateError(ValueError): ... -def _dnsname_match(dn, hostname: str, max_wildcards: int = 1) -> Union[bool, None, Match[str]]: ... -def _ipaddress_match(ipname: str, host_ip: str) -> bool: ... def match_hostname(cert: Mapping[str, Any], hostname: str) -> None: ... diff --git a/pymongo/ssl_support.pyi b/pymongo/ssl_support.pyi index aaa5b64859..790d8397f2 100644 --- a/pymongo/ssl_support.pyi +++ b/pymongo/ssl_support.pyi @@ -1,5 +1,7 @@ -from typing import Any, Union +from typing import Any, Optional, Union +from pymongo.ssl_context import SSLContext as SSLContext -def validate_cert_reqs(option: str, value: Union[str, int]) -> Any: ... -def _load_wincerts() -> None: ... +HAVE_SSL: bool = ... + +def validate_cert_reqs(option: str, value: Optional[Union[str, int]]) -> Any: ... def get_ssl_context(*args: Any) -> Any: ... diff --git a/pymongo/topology.pyi b/pymongo/topology.pyi index c7eb41a5b6..4315c3a382 100644 --- a/pymongo/topology.pyi +++ b/pymongo/topology.pyi @@ -1,26 +1,38 @@ -from typing import Callable, List, Optional, Sequence, Set, Tuple, Union -from queue import Queue +from typing import Any, Callable, List, Optional, Sequence, Set, Tuple, Union +import sys +if sys.version_info >= (3,): + from queue import Queue +else: + from Queue import Queue from pymongo.pool import Pool from pymongo.server import Server from pymongo.server_description import ServerDescription from pymongo.server_selectors import Selection from pymongo.settings import TopologySettings +from pymongo.topology_description import TopologyDescription, TOPOLOGY_TYPE as TOPOLOGY_TYPE -def process_events_queue(queue_ref: Queue) -> bool: ... +def process_events_queue(queue_ref: Queue[Tuple[Callable[..., Any], Sequence[Any]]]) -> bool: ... class Topology(object): def __init__(self, topology_settings: TopologySettings) -> None: ... def open(self) -> None: ... - def select_servers(self, selector: Callable[[Sequence[Server]], Sequence[Server]], server_selection_timeout: Optional[int] = ..., address: Optional[Tuple[str, int]] = ...) -> List[Server]: ... - def select_server(self, selector: Callable[[Sequence[Server]], Sequence[Server]], server_selection_timeout: Optional[int] = ..., address: Optional[Tuple[str, int]] = ...) -> Server: ... + def select_servers( + self, + selector: Callable[[Sequence[Server]], Sequence[Server]], + server_selection_timeout: Optional[int] = ..., + address: Optional[Tuple[str, int]] = ...) -> List[Server]: ... + def select_server( + self, + selector: Callable[[Sequence[Server]], Sequence[Server]], + server_selection_timeout: Optional[int] = ..., + address: Optional[Tuple[str, int]] = ...) -> Server: ... def select_server_by_address(self, address: Tuple[str, int], server_selection_timeout: Optional[int] = ...) -> Server: ... def on_change(self, server_description: ServerDescription) -> None: ... def get_server_by_address(self, address: Tuple[str, int]) -> Optional[Server]: ... def has_server(self, address: Tuple[str, int]) -> bool: ... def get_primary(self) -> Optional[Tuple[str, int]]: ... - def _get_replica_set_members(self, selector: Callable[[Selection], Sequence[ServerDescription]]) -> Set[Tuple[str, int]]: ... def get_secondaries(self) -> Set[Tuple[str, int]]: ... def get_arbiters(self) -> Set[Tuple[str, int]]: ... def request_check_all(self, wait_time: int = ...) -> None: ... @@ -30,13 +42,4 @@ class Topology(object): def update_pool(self) -> None: ... def close(self) -> None: ... @property - def description(self) -> ServerDescription: ... - def _new_selection(self) -> Selection: ... - def _ensure_opened(self) -> None: ... - def _reset_server(self, address: Tuple[str, int]) -> None: ... - def _request_check(self, address: Tuple[str, int]) -> None: ... - def _request_check_all(self) -> None: ... - def _update_servers(self) -> None: ... - def _create_pool_for_server(self, address: Tuple[str, int]) -> Pool: ... - def _create_pool_for_monitor(self, address: Tuple[str, int]) -> Pool: ... - def _error_message(self, selector: Callable[[Selection], Selection]) -> str: ... + def description(self) -> TopologyDescription: ... diff --git a/pymongo/topology_description.pyi b/pymongo/topology_description.pyi index cd9cc65af6..e12164336c 100644 --- a/pymongo/topology_description.pyi +++ b/pymongo/topology_description.pyi @@ -7,16 +7,25 @@ from pymongo.server_selectors import Selection from pymongo.settings import TopologySettings -class TopologyType(NamedTuple): - Single: int - ReplicaSetNoPrimary: int - ReplicaSetWithPrimary: int - Sharded: int - Unknown: int +TopologyType = NamedTuple('TopologyType', [ + ('Single', int), + ('ReplicaSetNoPrimary', int), + ('ReplicaSetWithPrimary', int), + ('Sharded', int), + ('Unknown', int), +]) TOPOLOGY_TYPE: TopologyType = ... class TopologyDescription(object): - def __init__(self, topology_type: int, server_descriptions: Mapping[Tuple[str, int], ServerDescription], replica_set_name: Optional[str], max_set_version: Optional[int], max_election_id: Optional[int], topology_settings: TopologySettings) -> None: ... + def __init__( + self, + topology_type: int, + server_descriptions: Mapping[Tuple[str, int], + ServerDescription], + replica_set_name: Optional[str], + max_set_version: Optional[int], + max_election_id: Optional[int], + topology_settings: TopologySettings) -> None: ... def check_compatible(self) -> None: ... def has_server(self, address: Tuple[str, int]) -> bool: ... def reset_server(self, address: Tuple[str, int]) -> 'TopologyDescription': ... @@ -38,13 +47,13 @@ class TopologyDescription(object): def common_wire_version(self) -> Optional[int]: ... @property def heartbeat_frequency(self) -> int: ... - def apply_selector(self, selector: Union[Selection, Callable[[Selection], Selection], _ServerMode], address: Tuple[str, int]) -> List[ServerDescription]: ... + def apply_selector( + self, + selector: Union[Selection, Callable[[Selection], Selection], _ServerMode], + address: Tuple[str, int]) -> List[ServerDescription]: ... def has_readable_server(self, read_preference: _ServerMode = ...) -> bool: ... def has_writable_server(self) -> bool: ... -_SERVER_TYPE_TO_TOPOLOGY_TYPE: Dict[int, int] = ... -def updated_topology_description(topology_description: TopologyDescription, server_description: ServerDescription) -> TopologyDescription: ... -def _update_rs_from_primary(sds: Mapping[Tuple[str, int], ServerDescription], replica_set_name: str, server_description: ServerDescription, max_set_version: int, max_election_id: int) -> Tuple[int, str, int, int]: ... -def _update_rs_with_primary_from_member(sds: Mapping[Tuple[str, int], ServerDescription], replica_set_name: str, server_description: ServerDescription) -> int: ... -def _update_rs_no_primary_from_member(sds: Mapping[Tuple[str, int], ServerDescription], replica_set_name: str, server_description: ServerDescription) -> Tuple[int, str]: ... -def _check_has_primary(sds: Mapping[Tuple[str, int], ServerDescription]) -> int: ... +def updated_topology_description( + topology_description: TopologyDescription, + server_description: ServerDescription) -> TopologyDescription: ... diff --git a/pymongo/uri_parser.pyi b/pymongo/uri_parser.pyi new file mode 100644 index 0000000000..48b2bc67f1 --- /dev/null +++ b/pymongo/uri_parser.pyi @@ -0,0 +1,20 @@ +# Stubs for pymongo.uri_parser (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from bson.py3compat import abc +from typing import Any, Dict, List, Mapping, Optional, Tuple + +SCHEME: str = ... +SCHEME_LEN: int = ... +SRV_SCHEME: str = ... +SRV_SCHEME_LEN: int = ... +DEFAULT_PORT: int = ... + +def parse_userinfo(userinfo: str) -> Tuple[str, str]: ... +def parse_ipv6_literal_host(entity: str, default_port: int) -> Tuple[str, int]: ... +def parse_host(entity: str, default_port: int = ...) -> Tuple[str, int]: ... +def validate_options(opts: Mapping[str, Any], warn: bool = ...) -> Dict[str, Any]: ... +def split_options(opts: str, validate: bool = ..., warn: bool = ..., normalize: bool = ...) -> Dict[str, Any]: ... +def split_hosts(hosts: str, default_port: Any = ...) -> List[Tuple[str, int]]: ... +def parse_uri(uri: str, default_port: int = ..., validate: bool = ..., warn: bool = ...) -> Dict[str, Any]: ... diff --git a/pymongo/write_concern.pyi b/pymongo/write_concern.pyi index 7d67fab5b5..e6906142ed 100644 --- a/pymongo/write_concern.pyi +++ b/pymongo/write_concern.pyi @@ -1,7 +1,14 @@ from typing import Any, Dict, Optional, Union class WriteConcern(object): - def __init__(self, w: Optional[Union[int, str]] = ..., wtimeout: Optional[int] = ..., j: Optional[bool] = ..., fsync: Optional[bool] = ...) -> None: ... + def __init__( + self, + w: Optional[Union[int, str]] = ..., + wtimeout: Optional[int] = ..., + j: Optional[bool] = ..., + fsync: Optional[bool] = ...) -> None: ... + @property + def is_server_default(self) -> bool: ... @property def document(self) -> Dict[str, Any]: ... @property diff --git a/setup.py b/setup.py index 455313b8a7..2689438720 100755 --- a/setup.py +++ b/setup.py @@ -387,5 +387,9 @@ def build_extension(self, ext): "doc": doc, "test": test}, extras_require=extras_require, + package_data={ + 'bson': ['bson/py.typed', 'bson/*.pyi'], + 'pymongo': ['bson/py.typed', 'bson/*.pyi'], + }, **extra_opts )