Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions pymongo/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these imports necessary?


def has_c() -> bool: ...
29 changes: 29 additions & 0 deletions pymongo/auth.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should bother adding type hints to private functions/methods like this. Let's stick to things that are publicly documented.

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: ...
61 changes: 61 additions & 0 deletions pymongo/bulk.pyi
Original file line number Diff line number Diff line change
@@ -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]: ...
44 changes: 44 additions & 0 deletions pymongo/client_options.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
27 changes: 27 additions & 0 deletions pymongo/collation.pyi
Original file line number Diff line number Diff line change
@@ -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]]: ...
91 changes: 91 additions & 0 deletions pymongo/collection.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
24 changes: 24 additions & 0 deletions pymongo/command_cursor.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Loading