diff --git a/beanie/odm/documents.py b/beanie/odm/documents.py index ae97a3bf..b1dd8e81 100644 --- a/beanie/odm/documents.py +++ b/beanie/odm/documents.py @@ -1012,7 +1012,8 @@ def get_previous_changes(self) -> Dict[str, Any]: return {} return self._collect_updates( - self._previous_saved_state, self._saved_state # type: ignore + self._previous_saved_state, + self._saved_state, # type: ignore ) @saved_state_needed diff --git a/beanie/odm/interfaces/find.py b/beanie/odm/interfaces/find.py index 3f9fc7b6..e3892efa 100644 --- a/beanie/odm/interfaces/find.py +++ b/beanie/odm/interfaces/find.py @@ -26,9 +26,11 @@ from beanie.odm.settings.base import ItemSettings if TYPE_CHECKING: - from beanie.odm.documents import DocType + from beanie.odm.documents import Document + from beanie.odm.views import View DocumentProjectionType = TypeVar("DocumentProjectionType", bound=BaseModel) +FindType = TypeVar("FindType", bound=Union["Document", "View"]) class FindInterface: @@ -54,7 +56,7 @@ def get_settings(cls) -> ItemSettings: @overload @classmethod def find_one( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], *args: Union[Mapping[str, Any], bool], projection_model: None = None, session: Optional[ClientSession] = None, @@ -62,13 +64,13 @@ def find_one( # type: ignore fetch_links: bool = False, with_children: bool = False, **pymongo_kwargs, - ) -> FindOne["DocType"]: + ) -> FindOne[FindType]: ... @overload @classmethod def find_one( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], *args: Union[Mapping[str, Any], bool], projection_model: Type["DocumentProjectionType"], session: Optional[ClientSession] = None, @@ -81,7 +83,7 @@ def find_one( # type: ignore @classmethod def find_one( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], *args: Union[Mapping[str, Any], bool], projection_model: Optional[Type["DocumentProjectionType"]] = None, session: Optional[ClientSession] = None, @@ -89,7 +91,7 @@ def find_one( # type: ignore fetch_links: bool = False, with_children: bool = False, **pymongo_kwargs, - ) -> Union[FindOne["DocType"], FindOne["DocumentProjectionType"]]: + ) -> Union[FindOne[FindType], FindOne["DocumentProjectionType"]]: """ Find one document by criteria. Returns [FindOne](query.md#findone) query object. @@ -115,7 +117,7 @@ def find_one( # type: ignore @overload @classmethod def find_many( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], *args: Union[Mapping[str, Any], bool], projection_model: None = None, skip: Optional[int] = None, @@ -127,13 +129,13 @@ def find_many( # type: ignore with_children: bool = False, lazy_parse: bool = False, **pymongo_kwargs, - ) -> FindMany["DocType"]: + ) -> FindMany[FindType]: ... @overload @classmethod def find_many( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], *args: Union[Mapping[str, Any], bool], projection_model: Optional[Type["DocumentProjectionType"]] = None, skip: Optional[int] = None, @@ -150,7 +152,7 @@ def find_many( # type: ignore @classmethod def find_many( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], *args: Union[Mapping[str, Any], bool], projection_model: Optional[Type["DocumentProjectionType"]] = None, skip: Optional[int] = None, @@ -162,7 +164,7 @@ def find_many( # type: ignore with_children: bool = False, lazy_parse: bool = False, **pymongo_kwargs, - ) -> Union[FindMany["DocType"], FindMany["DocumentProjectionType"]]: + ) -> Union[FindMany[FindType], FindMany["DocumentProjectionType"]]: """ Find many documents by criteria. Returns [FindMany](query.md#findmany) query object @@ -195,7 +197,7 @@ def find_many( # type: ignore @overload @classmethod def find( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], *args: Union[Mapping[str, Any], bool], projection_model: None = None, skip: Optional[int] = None, @@ -207,13 +209,13 @@ def find( # type: ignore with_children: bool = False, lazy_parse: bool = False, **pymongo_kwargs, - ) -> FindMany["DocType"]: + ) -> FindMany[FindType]: ... @overload @classmethod def find( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], *args: Union[Mapping[str, Any], bool], projection_model: Type["DocumentProjectionType"], skip: Optional[int] = None, @@ -230,7 +232,7 @@ def find( # type: ignore @classmethod def find( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], *args: Union[Mapping[str, Any], bool], projection_model: Optional[Type["DocumentProjectionType"]] = None, skip: Optional[int] = None, @@ -242,7 +244,7 @@ def find( # type: ignore with_children: bool = False, lazy_parse: bool = False, **pymongo_kwargs, - ) -> Union[FindMany["DocType"], FindMany["DocumentProjectionType"]]: + ) -> Union[FindMany[FindType], FindMany["DocumentProjectionType"]]: """ The same as find_many """ @@ -263,7 +265,7 @@ def find( # type: ignore @overload @classmethod def find_all( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], skip: Optional[int] = None, limit: Optional[int] = None, sort: Union[None, str, List[Tuple[str, SortDirection]]] = None, @@ -273,13 +275,13 @@ def find_all( # type: ignore with_children: bool = False, lazy_parse: bool = False, **pymongo_kwargs, - ) -> FindMany["DocType"]: + ) -> FindMany[FindType]: ... @overload @classmethod def find_all( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], skip: Optional[int] = None, limit: Optional[int] = None, sort: Union[None, str, List[Tuple[str, SortDirection]]] = None, @@ -294,7 +296,7 @@ def find_all( # type: ignore @classmethod def find_all( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], skip: Optional[int] = None, limit: Optional[int] = None, sort: Union[None, str, List[Tuple[str, SortDirection]]] = None, @@ -304,7 +306,7 @@ def find_all( # type: ignore with_children: bool = False, lazy_parse: bool = False, **pymongo_kwargs, - ) -> Union[FindMany["DocType"], FindMany["DocumentProjectionType"]]: + ) -> Union[FindMany[FindType], FindMany["DocumentProjectionType"]]: """ Get all the documents @@ -332,7 +334,7 @@ def find_all( # type: ignore @overload @classmethod def all( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], projection_model: None = None, skip: Optional[int] = None, limit: Optional[int] = None, @@ -342,13 +344,13 @@ def all( # type: ignore with_children: bool = False, lazy_parse: bool = False, **pymongo_kwargs, - ) -> FindMany["DocType"]: + ) -> FindMany[FindType]: ... @overload @classmethod def all( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], projection_model: Type["DocumentProjectionType"], skip: Optional[int] = None, limit: Optional[int] = None, @@ -363,7 +365,7 @@ def all( # type: ignore @classmethod def all( # type: ignore - cls: Type["DocType"], + cls: Type[FindType], projection_model: Optional[Type["DocumentProjectionType"]] = None, skip: Optional[int] = None, limit: Optional[int] = None, @@ -373,7 +375,7 @@ def all( # type: ignore with_children: bool = False, lazy_parse: bool = False, **pymongo_kwargs, - ) -> Union[FindMany["DocType"], FindMany["DocumentProjectionType"]]: + ) -> Union[FindMany[FindType], FindMany["DocumentProjectionType"]]: """ the same as find_all """