From 59689c837866d195f583d4ad8c504c870e77828a Mon Sep 17 00:00:00 2001 From: Dave Brondsema Date: Thu, 15 Aug 2024 12:03:04 -0400 Subject: [PATCH] add missing type annotations for a few methods & props on .m. and .query. --- ming/metadata.pyi | 12 ++++++++---- ming/odm/mapper.pyi | 9 ++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ming/metadata.pyi b/ming/metadata.pyi index 181044e..ea08f9e 100644 --- a/ming/metadata.pyi +++ b/ming/metadata.pyi @@ -2,12 +2,14 @@ from bson import ObjectId from datetime import datetime from typing import Generic, TypeVar, Any, Optional, overload, List, Dict, Type, Union, Mapping, type_check_only from pymongo.results import UpdateResult, DeleteResult +from pymongo.command_cursor import CommandCursor import bson from ming.base import Cursor from . import schema from .base import Object +from .session import Session AnyType = TypeVar('AnyType') @@ -181,6 +183,9 @@ M = TypeVar('M') MongoFilter = dict SaveResult = Union[ObjectId, Any] class _ClassManager(Generic[M]): + session: Session + collection_name: str + # proxies these from Session def get(self, **kwargs) -> Optional[M]: ... def find(self, filter: MongoFilter = None, *args, **kwargs) -> Cursor[M]: ... @@ -196,13 +201,12 @@ class _ClassManager(Generic[M]): def find_one_and_update(self, **kwargs) -> M: ... def find_one_and_replace(self, **kwargs) -> M: ... def find_one_and_delete(self, **kwargs) -> M: ... + def aggregate(self, pipeline: list, **kwargs) -> CommandCursor: ... + def distinct(self, key: str, filter: MongoFilter | None = None, **kwargs) -> list: ... """ - def group(self) -> int: ... def ensure_indexes(self) -> int: ... def index_information(self) -> int: ... def drop_indexes(self) -> int: ... - def aggregate(self) -> int: ... - def distinct(self) -> int: ... """ class _InstanceManager: @@ -219,4 +223,4 @@ class _InstanceManager: class Manager(_ClassManager[M], _InstanceManager): ... -def __getattr__(name) -> Any: ... # marks file as incomplete \ No newline at end of file +def __getattr__(name) -> Any: ... # marks file as incomplete diff --git a/ming/odm/mapper.pyi b/ming/odm/mapper.pyi index aab3092..02f593f 100644 --- a/ming/odm/mapper.pyi +++ b/ming/odm/mapper.pyi @@ -1,6 +1,8 @@ from typing import type_check_only, TypeVar, Generic, Optional, Union, Any, Dict, overload from bson import ObjectId +from pymongo.command_cursor import CommandCursor + from ming.base import Cursor M = TypeVar('M') @@ -18,11 +20,8 @@ class _ClassQuery(Generic[M]): def find_one_and_replace(self, **kwargs) -> M: ... def find_one_and_delete(self, **kwargs) -> M: ... def update_partial(self, filter: MongoFilter, fields: dict, **kwargs) -> ChangeResult: ... - """ - def group(self) -> int: ... - def distinct(self) -> int: ... - def aggregate(self) -> int: ... - """ + def aggregate(self, pipeline: list, **kwargs) -> CommandCursor: ... + def distinct(self, key: str, filter: MongoFilter | None = None, **kwargs) -> list: ... class _InstQuery(object): # proxied from session: