Skip to content

Commit

Permalink
Fix kwargs/args untyped (#1049)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: ᑕᗩᑭTᗩIᑎᗰᗩᖇᐯᗴᒪ <[email protected]>
  • Loading branch information
CAPITAINMARVEL and CAPITAINMARVEL authored Oct 15, 2024
1 parent 3421d55 commit f9d79ff
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 85 deletions.
2 changes: 1 addition & 1 deletion beanie/executors/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions beanie/migrations/controllers/free_fall.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions beanie/migrations/controllers/iterative.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions beanie/odm/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -691,13 +691,13 @@ async def replace_many(
@save_state_after
async def update(
self: Self,
*args,
*args: Union[Dict[Any, Any], Mapping[Any, Any]],
ignore_revision: bool = False,
session: Optional[AsyncIOMotorClientSession] = None,
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
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1161,7 +1161,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))
Expand Down Expand Up @@ -1227,7 +1227,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,
Expand Down Expand Up @@ -1264,7 +1264,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,
Expand Down Expand Up @@ -1296,7 +1296,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},
Expand Down Expand Up @@ -1327,7 +1327,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},
Expand Down
4 changes: 2 additions & 2 deletions beanie/odm/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions beanie/odm/interfaces/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion beanie/odm/interfaces/aggregation_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def aggregate(
self,
aggregation_pipeline,
projection_model=None,
session=None,
session: Optional[AsyncIOMotorClientSession] = None,
ignore_cache: bool = False,
): ...

Expand Down
30 changes: 15 additions & 15 deletions beanie/odm/interfaces/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit f9d79ff

Please sign in to comment.