From fba27997bbf623aba9494c30bdc6551dcea15adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Thu, 10 Oct 2024 19:11:10 +0200 Subject: [PATCH 01/11] fix kwargs and pymongo kwargs untyped --- beanie/odm/documents.py | 28 ++++++++++---------- beanie/odm/fields.py | 2 +- beanie/odm/interfaces/aggregate.py | 6 ++--- beanie/odm/interfaces/find.py | 30 ++++++++++----------- beanie/odm/interfaces/update.py | 2 +- beanie/odm/queries/aggregation.py | 2 +- beanie/odm/queries/delete.py | 2 +- beanie/odm/queries/find.py | 42 +++++++++++++++--------------- beanie/odm/queries/update.py | 14 +++++----- pyproject.toml | 1 + 10 files changed, 65 insertions(+), 64 deletions(-) diff --git a/beanie/odm/documents.py b/beanie/odm/documents.py index d2e2c682..42fa061e 100644 --- a/beanie/odm/documents.py +++ b/beanie/odm/documents.py @@ -254,7 +254,7 @@ async def get( with_children: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Optional["DocType"]: """ Get document by id, returns None if document does not exist @@ -436,7 +436,7 @@ async def insert_many( documents: Iterable[DocType], session: Optional[AsyncIOMotorClientSession] = None, link_rule: WriteRules = WriteRules.DO_NOTHING, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> InsertManyResult: """ Insert many documents to the collection @@ -553,7 +553,7 @@ async def save( session: Optional[AsyncIOMotorClientSession] = None, link_rule: WriteRules = WriteRules.DO_NOTHING, ignore_revision: bool = False, - **kwargs, + **kwargs: Any, ) -> Self: """ Update an existing model in the database or @@ -697,7 +697,7 @@ async def update( bulk_writer: Optional[BulkWriter] = None, skip_actions: Optional[List[Union[ActionDirections, str]]] = None, skip_sync: Optional[bool] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Self: """ Partially update the document in the database @@ -750,7 +750,7 @@ def update_all( *args: Union[dict, Mapping], session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> UpdateMany: """ Partially update all the documents @@ -771,7 +771,7 @@ def set( session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, skip_sync: Optional[bool] = None, - **kwargs, + **kwargs: Any, ) -> Coroutine[None, None, Self]: """ Set values @@ -810,7 +810,7 @@ def current_date( session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, skip_sync: Optional[bool] = None, - **kwargs, + **kwargs: Any, ) -> Coroutine[None, None, Self]: """ Set current date @@ -837,7 +837,7 @@ def inc( session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, skip_sync: Optional[bool] = None, - **kwargs, + **kwargs: Any, ) -> Coroutine[None, None, Self]: """ Increment @@ -876,7 +876,7 @@ async def delete( bulk_writer: Optional[BulkWriter] = None, link_rule: DeleteRules = DeleteRules.DO_NOTHING, skip_actions: Optional[List[Union[ActionDirections, str]]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Optional[DeleteResult]: """ Delete the document @@ -931,7 +931,7 @@ async def delete_all( cls, session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Optional[DeleteResult]: """ Delete all the documents @@ -1226,7 +1226,7 @@ async def hard_delete( bulk_writer: Optional[BulkWriter] = None, link_rule: DeleteRules = DeleteRules.DO_NOTHING, skip_actions: Optional[List[Union[ActionDirections, str]]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Optional[DeleteResult]: return await super().delete( session=session, @@ -1263,7 +1263,7 @@ def find_many_in_all( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[FindMany[FindType], FindMany["DocumentProjectionType"]]: return cls._find_many_query_class(document_model=cls).find_many( *args, @@ -1295,7 +1295,7 @@ def find_many( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[FindMany[FindType], FindMany["DocumentProjectionType"]]: args = cls._add_class_id_filter(args, with_children) + ( {"deleted_at": None}, @@ -1326,7 +1326,7 @@ def find_one( # type: ignore with_children: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[FindOne[FindType], FindOne["DocumentProjectionType"]]: args = cls._add_class_id_filter(args, with_children) + ( {"deleted_at": None}, diff --git a/beanie/odm/fields.py b/beanie/odm/fields.py index c2a95e77..4250d722 100644 --- a/beanie/odm/fields.py +++ b/beanie/odm/fields.py @@ -84,7 +84,7 @@ class IndexedAnnotation: _indexed: Tuple[int, Dict[str, Any]] -def Indexed(typ=None, index_type=ASCENDING, **kwargs): +def Indexed(typ=None, index_type=ASCENDING, **kwargs: Any): """ If `typ` is defined, returns a subclass of `typ` with an extra attribute `_indexed` as a tuple: diff --git a/beanie/odm/interfaces/aggregate.py b/beanie/odm/interfaces/aggregate.py index 62322095..eb907f2e 100644 --- a/beanie/odm/interfaces/aggregate.py +++ b/beanie/odm/interfaces/aggregate.py @@ -25,7 +25,7 @@ def aggregate( projection_model: None = None, session: Optional[AsyncIOMotorClientSession] = None, ignore_cache: bool = False, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> AggregationQuery[Dict[str, Any]]: ... @overload @@ -36,7 +36,7 @@ def aggregate( projection_model: Type[DocumentProjectionType], session: Optional[AsyncIOMotorClientSession] = None, ignore_cache: bool = False, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> AggregationQuery[DocumentProjectionType]: ... @classmethod @@ -46,7 +46,7 @@ def aggregate( projection_model: Optional[Type[DocumentProjectionType]] = None, session: Optional[AsyncIOMotorClientSession] = None, ignore_cache: bool = False, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[ AggregationQuery[Dict[str, Any]], AggregationQuery[DocumentProjectionType], diff --git a/beanie/odm/interfaces/find.py b/beanie/odm/interfaces/find.py index 114352d6..c96f5bf4 100644 --- a/beanie/odm/interfaces/find.py +++ b/beanie/odm/interfaces/find.py @@ -66,7 +66,7 @@ def find_one( # type: ignore with_children: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> FindOne[FindType]: ... @overload @@ -81,7 +81,7 @@ def find_one( # type: ignore with_children: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> FindOne["DocumentProjectionType"]: ... @classmethod @@ -95,7 +95,7 @@ def find_one( # type: ignore with_children: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[FindOne[FindType], FindOne["DocumentProjectionType"]]: """ Find one document by criteria. @@ -137,7 +137,7 @@ def find_many( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> FindMany[FindType]: ... @overload @@ -156,7 +156,7 @@ def find_many( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> FindMany["DocumentProjectionType"]: ... @classmethod @@ -174,7 +174,7 @@ def find_many( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[FindMany[FindType], FindMany["DocumentProjectionType"]]: """ Find many documents by criteria. @@ -223,7 +223,7 @@ def find( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> FindMany[FindType]: ... @overload @@ -242,7 +242,7 @@ def find( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> FindMany["DocumentProjectionType"]: ... @classmethod @@ -260,7 +260,7 @@ def find( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[FindMany[FindType], FindMany["DocumentProjectionType"]]: """ The same as find_many @@ -295,7 +295,7 @@ def find_all( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> FindMany[FindType]: ... @overload @@ -312,7 +312,7 @@ def find_all( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> FindMany["DocumentProjectionType"]: ... @classmethod @@ -328,7 +328,7 @@ def find_all( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[FindMany[FindType], FindMany["DocumentProjectionType"]]: """ Get all the documents @@ -370,7 +370,7 @@ def all( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> FindMany[FindType]: ... @overload @@ -387,7 +387,7 @@ def all( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> FindMany["DocumentProjectionType"]: ... @classmethod @@ -403,7 +403,7 @@ def all( # type: ignore lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[FindMany[FindType], FindMany["DocumentProjectionType"]]: """ the same as find_all diff --git a/beanie/odm/interfaces/update.py b/beanie/odm/interfaces/update.py index aeef2a3f..665fb62d 100644 --- a/beanie/odm/interfaces/update.py +++ b/beanie/odm/interfaces/update.py @@ -90,7 +90,7 @@ def inc( expression: Dict[Union[ExpressionField, float, int, str], Any], session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **kwargs, + **kwargs: Any, ): """ Increment diff --git a/beanie/odm/queries/aggregation.py b/beanie/odm/queries/aggregation.py index 477b1372..df328097 100644 --- a/beanie/odm/queries/aggregation.py +++ b/beanie/odm/queries/aggregation.py @@ -41,7 +41,7 @@ def __init__( find_query: Mapping[str, Any], projection_model: Optional[Type[BaseModel]] = None, ignore_cache: bool = False, - **pymongo_kwargs, + **pymongo_kwargs: Any, ): self.aggregation_pipeline: List[Mapping[str, Any]] = ( aggregation_pipeline diff --git a/beanie/odm/queries/delete.py b/beanie/odm/queries/delete.py index 4ccb4886..772bdd81 100644 --- a/beanie/odm/queries/delete.py +++ b/beanie/odm/queries/delete.py @@ -23,7 +23,7 @@ def __init__( document_model: Type["DocType"], find_query: Mapping[str, Any], bulk_writer: Optional[BulkWriter] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ): self.document_model = document_model self.find_query = find_query diff --git a/beanie/odm/queries/find.py b/beanie/odm/queries/find.py index 544eb52a..cbb179b0 100644 --- a/beanie/odm/queries/find.py +++ b/beanie/odm/queries/find.py @@ -113,7 +113,7 @@ def delete( self, session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[DeleteOne, DeleteMany]: """ Provide search criteria to the Delete query @@ -200,7 +200,7 @@ def find_many( lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> "FindMany[FindQueryResultType]": ... @overload @@ -217,7 +217,7 @@ def find_many( lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> "FindMany[FindQueryProjectionType]": ... def find_many( @@ -233,7 +233,7 @@ def find_many( lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[ "FindMany[FindQueryResultType]", "FindMany[FindQueryProjectionType]" ]: @@ -311,7 +311,7 @@ def find( lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> "FindMany[FindQueryResultType]": ... @overload @@ -328,7 +328,7 @@ def find( lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> "FindMany[FindQueryProjectionType]": ... def find( @@ -344,7 +344,7 @@ def find( lazy_parse: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[ "FindMany[FindQueryResultType]", "FindMany[FindQueryProjectionType]" ]: @@ -431,7 +431,7 @@ def update( *args: Mapping[str, Any], session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ): """ Create Update with modifications query @@ -457,7 +457,7 @@ def upsert( *args: Mapping[str, Any], on_insert: "DocType", session: Optional[AsyncIOMotorClientSession] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ): """ Create Update with modifications query @@ -488,7 +488,7 @@ def update_many( *args: Mapping[str, Any], session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> UpdateMany: """ Provide search criteria to the @@ -512,7 +512,7 @@ def delete_many( self, session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> DeleteMany: """ Provide search criteria to the [DeleteMany](query.md#deletemany) query @@ -537,7 +537,7 @@ def aggregate( projection_model: None = None, session: Optional[AsyncIOMotorClientSession] = None, ignore_cache: bool = False, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> AggregationQuery[Dict[str, Any]]: ... @overload @@ -547,7 +547,7 @@ def aggregate( projection_model: Type[FindQueryProjectionType], session: Optional[AsyncIOMotorClientSession] = None, ignore_cache: bool = False, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> AggregationQuery[FindQueryProjectionType]: ... def aggregate( @@ -556,7 +556,7 @@ def aggregate( projection_model: Optional[Type[FindQueryProjectionType]] = None, session: Optional[AsyncIOMotorClientSession] = None, ignore_cache: bool = False, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[ AggregationQuery[Dict[str, Any]], AggregationQuery[FindQueryProjectionType], @@ -771,7 +771,7 @@ def find_one( fetch_links: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> "FindOne[FindQueryResultType]": ... @overload @@ -784,7 +784,7 @@ def find_one( fetch_links: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> "FindOne[FindQueryProjectionType]": ... def find_one( @@ -796,7 +796,7 @@ def find_one( fetch_links: bool = False, nesting_depth: Optional[int] = None, nesting_depths_per_field: Optional[Dict[str, int]] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> Union[ "FindOne[FindQueryResultType]", "FindOne[FindQueryProjectionType]" ]: @@ -826,7 +826,7 @@ def update( session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, response_type: Optional[UpdateResponse] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ): """ Create Update with modifications query @@ -859,7 +859,7 @@ def upsert( on_insert: "DocType", session: Optional[AsyncIOMotorClientSession] = None, response_type: Optional[UpdateResponse] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ): """ Create Update with modifications query @@ -893,7 +893,7 @@ def update_one( session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, response_type: Optional[UpdateResponse] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> UpdateOne: """ Create [UpdateOne](query.md#updateone) query using modifications and @@ -918,7 +918,7 @@ def delete_one( self, session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> DeleteOne: """ Provide search criteria to the [DeleteOne](query.md#deleteone) query diff --git a/beanie/odm/queries/update.py b/beanie/odm/queries/update.py index 8c53de6c..7a1b0849 100644 --- a/beanie/odm/queries/update.py +++ b/beanie/odm/queries/update.py @@ -109,7 +109,7 @@ def update( *args: Mapping[str, Any], session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> "UpdateQuery": """ Provide modifications to the update query. @@ -132,7 +132,7 @@ def upsert( *args: Mapping[str, Any], on_insert: "DocType", session: Optional[AsyncIOMotorClientSession] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> "UpdateQuery": """ Provide modifications to the upsert query. @@ -153,7 +153,7 @@ def update_many( *args: Mapping[str, Any], session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ): """ Provide modifications to the update query @@ -230,7 +230,7 @@ def update( session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, response_type: Optional[UpdateResponse] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> "UpdateQuery": """ Provide modifications to the update query. @@ -257,7 +257,7 @@ def upsert( on_insert: "DocType", session: Optional[AsyncIOMotorClientSession] = None, response_type: Optional[UpdateResponse] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) -> "UpdateQuery": """ Provide modifications to the upsert query. @@ -285,7 +285,7 @@ def update_one( session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, response_type: Optional[UpdateResponse] = None, - **pymongo_kwargs, + **pymongo_kwargs: Any, ): """ Provide modifications to the update query. The same as `update()` @@ -302,7 +302,7 @@ def update_one( session=session, bulk_writer=bulk_writer, response_type=response_type, - **pymongo_kwargs, + **pymongo_kwargs: Any, ) async def _update(self): diff --git a/pyproject.toml b/pyproject.toml index d485217c..39d3fb2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,6 +103,7 @@ ignore_missing_imports = true [tool.pyright] include = ["tests/typing", "beanie"] +typeCheckingMode = "strict" [tool.ruff] line-length = 79 From 06d0b402b5ca5fa77c1f7320d834f8e8ea95f512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Thu, 10 Oct 2024 19:11:36 +0200 Subject: [PATCH 02/11] oops --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 39d3fb2d..d485217c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,7 +103,6 @@ ignore_missing_imports = true [tool.pyright] include = ["tests/typing", "beanie"] -typeCheckingMode = "strict" [tool.ruff] line-length = 79 From 58edc8f95dee3fb592073de9c18ee4cd491258fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Thu, 10 Oct 2024 19:12:24 +0200 Subject: [PATCH 03/11] fix formatting --- beanie/odm/queries/update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beanie/odm/queries/update.py b/beanie/odm/queries/update.py index 7a1b0849..7c17412a 100644 --- a/beanie/odm/queries/update.py +++ b/beanie/odm/queries/update.py @@ -302,7 +302,7 @@ def update_one( session=session, bulk_writer=bulk_writer, response_type=response_type, - **pymongo_kwargs: Any, + **pymongo_kwargs, ) async def _update(self): From 18a8a420cb3ade404b13e9f6c6e8e94c7d5f8de2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Thu, 10 Oct 2024 19:42:37 +0200 Subject: [PATCH 04/11] fix other unknown type --- beanie/odm/cache.py | 2 +- beanie/odm/interfaces/aggregation_methods.py | 2 +- beanie/odm/interfaces/update.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/beanie/odm/cache.py b/beanie/odm/cache.py index f5297d48..60be24cb 100644 --- a/beanie/odm/cache.py +++ b/beanie/odm/cache.py @@ -19,7 +19,7 @@ def __init__(self, capacity: int, expiration_time: timedelta): self.expiration_time: timedelta = expiration_time self.cache: collections.OrderedDict = collections.OrderedDict() - def get(self, key) -> Optional[CachedItem]: + def get(self, key: Any) -> Optional[CachedItem]: try: item: CachedItem = self.cache.pop(key) if ( diff --git a/beanie/odm/interfaces/aggregation_methods.py b/beanie/odm/interfaces/aggregation_methods.py index 8db76bff..6acdd7b8 100644 --- a/beanie/odm/interfaces/aggregation_methods.py +++ b/beanie/odm/interfaces/aggregation_methods.py @@ -16,7 +16,7 @@ def aggregate( self, aggregation_pipeline, projection_model=None, - session=None, + session: Optional[AsyncIOMotorClientSession] = None, ignore_cache: bool = False, ): ... diff --git a/beanie/odm/interfaces/update.py b/beanie/odm/interfaces/update.py index 665fb62d..d7881839 100644 --- a/beanie/odm/interfaces/update.py +++ b/beanie/odm/interfaces/update.py @@ -24,7 +24,7 @@ def update( *args: Mapping[str, Any], session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **kwargs, + **kwargs: Any, ): return self @@ -33,7 +33,7 @@ def set( expression: Dict[Union[ExpressionField, str, Any], Any], session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **kwargs, + **kwargs: Any, ): """ Set values @@ -66,7 +66,7 @@ def current_date( expression: Dict[Union[datetime, ExpressionField, str], Any], session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, - **kwargs, + **kwargs: Any, ): """ Set current date From dd4f7a0ed819abe9d942086cd3b944621f7d85df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Thu, 10 Oct 2024 20:32:40 +0200 Subject: [PATCH 05/11] last --- beanie/odm/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beanie/odm/cache.py b/beanie/odm/cache.py index 60be24cb..f5297d48 100644 --- a/beanie/odm/cache.py +++ b/beanie/odm/cache.py @@ -19,7 +19,7 @@ def __init__(self, capacity: int, expiration_time: timedelta): self.expiration_time: timedelta = expiration_time self.cache: collections.OrderedDict = collections.OrderedDict() - def get(self, key: Any) -> Optional[CachedItem]: + def get(self, key) -> Optional[CachedItem]: try: item: CachedItem = self.cache.pop(key) if ( From 2582c6094da8e9f5f89fe1d991dfa98af15b30a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Thu, 10 Oct 2024 21:33:00 +0200 Subject: [PATCH 06/11] add missing update type hint --- beanie/odm/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beanie/odm/documents.py b/beanie/odm/documents.py index 42fa061e..33a86603 100644 --- a/beanie/odm/documents.py +++ b/beanie/odm/documents.py @@ -691,7 +691,7 @@ async def replace_many( @save_state_after async def update( self: Self, - *args, + *args: Any, ignore_revision: bool = False, session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, From 96741c22b644157f4fedba6c6b80ef29b6658dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Fri, 11 Oct 2024 10:16:01 +0200 Subject: [PATCH 07/11] added missing kwargs/args type hint --- beanie/executors/migrate.py | 2 +- beanie/migrations/controllers/free_fall.py | 4 ++-- beanie/migrations/controllers/iterative.py | 4 ++-- beanie/odm/documents.py | 4 ++-- beanie/odm/fields.py | 2 +- beanie/odm/operators/find/array.py | 4 ++-- beanie/odm/queries/update.py | 2 +- beanie/odm/utils/pydantic.py | 2 +- beanie/odm/utils/state.py | 12 ++++++++---- pyproject.toml | 1 + 10 files changed, 21 insertions(+), 16 deletions(-) diff --git a/beanie/executors/migrate.py b/beanie/executors/migrate.py index 2e6f62b4..d19c3a2d 100644 --- a/beanie/executors/migrate.py +++ b/beanie/executors/migrate.py @@ -18,7 +18,7 @@ class MigrationSettings: - def __init__(self, **kwargs): + def __init__(self, **kwargs: Any): self.direction = ( kwargs.get("direction") or self.get_env_value("direction") diff --git a/beanie/migrations/controllers/free_fall.py b/beanie/migrations/controllers/free_fall.py index 24a26290..31c40c8a 100644 --- a/beanie/migrations/controllers/free_fall.py +++ b/beanie/migrations/controllers/free_fall.py @@ -1,5 +1,5 @@ from inspect import signature -from typing import List, Type +from typing import Any, List, Type from beanie.migrations.controllers.base import BaseMigrationController from beanie.odm.documents import Document @@ -12,7 +12,7 @@ def __init__(self, function): self.function_signature = signature(function) self.document_models = document_models - def __call__(self, *args, **kwargs): + def __call__(self, *args: Any, **kwargs: Any): pass @property diff --git a/beanie/migrations/controllers/iterative.py b/beanie/migrations/controllers/iterative.py index 63d0594c..6368e92a 100644 --- a/beanie/migrations/controllers/iterative.py +++ b/beanie/migrations/controllers/iterative.py @@ -1,6 +1,6 @@ import asyncio from inspect import isclass, signature -from typing import List, Optional, Type, Union +from typing import Any, List, Optional, Type, Union from beanie.migrations.controllers.base import BaseMigrationController from beanie.migrations.utils import update_dict @@ -77,7 +77,7 @@ def __init__(self, function): self.batch_size = batch_size - def __call__(self, *args, **kwargs): + def __call__(self, *args: Any, **kwargs: Any): pass @property diff --git a/beanie/odm/documents.py b/beanie/odm/documents.py index 33a86603..a072b069 100644 --- a/beanie/odm/documents.py +++ b/beanie/odm/documents.py @@ -204,7 +204,7 @@ class Config: # Database _database_major_version: ClassVar[int] = 4 - def __init__(self, *args, **kwargs) -> None: + def __init__(self, *args: Any, **kwargs: Any) -> None: super(Document, self).__init__(*args, **kwargs) self.get_motor_collection() @@ -1160,7 +1160,7 @@ def check_hidden_fields(cls): cls.__exclude_fields__[name] = True @wrap_with_actions(event_type=EventTypes.VALIDATE_ON_SAVE) - async def validate_self(self, *args, **kwargs): + async def validate_self(self, *args: Any, **kwargs: Any): # TODO: it can be sync, but needs some actions controller improvements if self.get_settings().validate_on_save: new_model = parse_model(self.__class__, get_model_dump(self)) diff --git a/beanie/odm/fields.py b/beanie/odm/fields.py index 4250d722..c93cc892 100644 --- a/beanie/odm/fields.py +++ b/beanie/odm/fields.py @@ -109,7 +109,7 @@ class MyModel(BaseModel): class NewType(typ): _indexed = (index_type, kwargs) - def __new__(cls, *args, **kwargs): + def __new__(cls, *args: Any, **kwargs: Any): return typ.__new__(typ, *args, **kwargs) if IS_PYDANTIC_V2: diff --git a/beanie/odm/operators/find/array.py b/beanie/odm/operators/find/array.py index ea6c24f4..dd924ec5 100644 --- a/beanie/odm/operators/find/array.py +++ b/beanie/odm/operators/find/array.py @@ -1,5 +1,5 @@ from abc import ABC -from typing import Optional +from typing import Any, Optional from beanie.odm.operators.find import BaseFindOperator @@ -70,7 +70,7 @@ def __init__( self, field, expression: Optional[dict] = None, - **kwargs, + **kwargs: Any, ): self.field = field diff --git a/beanie/odm/queries/update.py b/beanie/odm/queries/update.py index 7c17412a..16ecd7c7 100644 --- a/beanie/odm/queries/update.py +++ b/beanie/odm/queries/update.py @@ -220,7 +220,7 @@ class UpdateOne(UpdateQuery): Update One query class """ - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any): super(UpdateOne, self).__init__(*args, **kwargs) self.response_type = UpdateResponse.UPDATE_RESULT diff --git a/beanie/odm/utils/pydantic.py b/beanie/odm/utils/pydantic.py index d94a9c50..ac486aa1 100644 --- a/beanie/odm/utils/pydantic.py +++ b/beanie/odm/utils/pydantic.py @@ -55,7 +55,7 @@ def get_config_value(model, parameter: str): return getattr(model.Config, parameter, None) -def get_model_dump(model, *args, **kwargs): +def get_model_dump(model, *args: Any, **kwargs: Any): if IS_PYDANTIC_V2: return model.model_dump(*args, **kwargs) else: diff --git a/beanie/odm/utils/state.py b/beanie/odm/utils/state.py index f609fe5a..80c3ac9b 100644 --- a/beanie/odm/utils/state.py +++ b/beanie/odm/utils/state.py @@ -26,12 +26,14 @@ def saved_state_needed( f: "AnyDocMethod[DocType, P, R]", ) -> "AnyDocMethod[DocType, P, R]": @wraps(f) - def sync_wrapper(self: "DocType", *args, **kwargs): + def sync_wrapper(self: "DocType", *args: P.args, **kwargs: P.kwargs) -> R: check_if_state_saved(self) return f(self, *args, **kwargs) @wraps(f) - async def async_wrapper(self: "DocType", *args, **kwargs): + async def async_wrapper( + self: "DocType", *args: P.args, **kwargs: P.kwargs + ) -> R: check_if_state_saved(self) # type ignore because there is no nice/proper way to annotate both sync # and async case without parametrized TypeVar, which is not supported @@ -59,12 +61,14 @@ def previous_saved_state_needed( f: "AnyDocMethod[DocType, P, R]", ) -> "AnyDocMethod[DocType, P, R]": @wraps(f) - def sync_wrapper(self: "DocType", *args, **kwargs): + def sync_wrapper(self: "DocType", *args: P.args, **kwargs: P.kwargs) -> R: check_if_previous_state_saved(self) return f(self, *args, **kwargs) @wraps(f) - async def async_wrapper(self: "DocType", *args, **kwargs): + async def async_wrapper( + self: "DocType", *args: P.args, **kwargs: P.kwargs + ) -> R: check_if_previous_state_saved(self) # type ignore because there is no nice/proper way to annotate both sync # and async case without parametrized TypeVar, which is not supported diff --git a/pyproject.toml b/pyproject.toml index d485217c..39d3fb2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,6 +103,7 @@ ignore_missing_imports = true [tool.pyright] include = ["tests/typing", "beanie"] +typeCheckingMode = "strict" [tool.ruff] line-length = 79 From 2b44f9145c034e65fb8200b1f52a35116600345c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Fri, 11 Oct 2024 10:17:05 +0200 Subject: [PATCH 08/11] accidentally changed pyproject --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 39d3fb2d..d485217c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,7 +103,6 @@ ignore_missing_imports = true [tool.pyright] include = ["tests/typing", "beanie"] -typeCheckingMode = "strict" [tool.ruff] line-length = 79 From 04916d58b7b9b436dab812ba1d02e3e2d04e94f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Sun, 13 Oct 2024 10:07:57 +0200 Subject: [PATCH 09/11] fix args type hint --- beanie/odm/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beanie/odm/documents.py b/beanie/odm/documents.py index a072b069..0b071298 100644 --- a/beanie/odm/documents.py +++ b/beanie/odm/documents.py @@ -691,7 +691,7 @@ async def replace_many( @save_state_after async def update( self: Self, - *args: Any, + *args: Union[dict[Any, Any], Mapping[Any, Any]], ignore_revision: bool = False, session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None, From 000de08d40365ac0fb2dbf67a6d40e1b2aa3d58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Sun, 13 Oct 2024 10:21:33 +0200 Subject: [PATCH 10/11] fix update args --- beanie/odm/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beanie/odm/documents.py b/beanie/odm/documents.py index 0b071298..50fd1e18 100644 --- a/beanie/odm/documents.py +++ b/beanie/odm/documents.py @@ -709,7 +709,7 @@ async def update( :param pymongo_kwargs: pymongo native parameters for update operation :return: self """ - arguments = list(args) + arguments: list[Any] = list(args) if skip_sync is not None: raise DeprecationWarning( From ab54c0ca1348b8ee0c6c6d5edb6973dfcc172405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=91=95=E1=97=A9=E1=91=ADT=E1=97=A9I=E1=91=8E=E1=97=B0?= =?UTF-8?q?=E1=97=A9=E1=96=87=E1=90=AF=E1=97=B4=E1=92=AA?= Date: Sun, 13 Oct 2024 10:35:41 +0200 Subject: [PATCH 11/11] fix use of dict instead of Dict --- beanie/odm/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beanie/odm/documents.py b/beanie/odm/documents.py index 50fd1e18..df3356d3 100644 --- a/beanie/odm/documents.py +++ b/beanie/odm/documents.py @@ -691,7 +691,7 @@ async def replace_many( @save_state_after async def update( self: Self, - *args: Union[dict[Any, Any], Mapping[Any, Any]], + *args: Union[Dict[Any, Any], Mapping[Any, Any]], ignore_revision: bool = False, session: Optional[AsyncIOMotorClientSession] = None, bulk_writer: Optional[BulkWriter] = None,