From d0a979391747120a2e421bc0634791a3c0000a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joon=20Hwan=20=EA=B9=80=EC=A4=80=ED=99=98?= Date: Sun, 28 Aug 2022 17:13:56 +0900 Subject: [PATCH] Add async queryset for Django 4.1 (#1131) * Add async queryset for Django 4.1 * dedup * fix to async --- django-stubs/db/models/manager.pyi | 26 ++++++++++++++++++++++++++ django-stubs/db/models/query.pyi | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/django-stubs/db/models/manager.pyi b/django-stubs/db/models/manager.pyi index 9383f62..b1b83ad 100644 --- a/django-stubs/db/models/manager.pyi +++ b/django-stubs/db/models/manager.pyi @@ -50,26 +50,51 @@ class BaseManager(Generic[_T]): # NOTE: The following methods are in common with QuerySet, but note that the use of QuerySet as a return type # rather than a self-type (_QS), since Manager's QuerySet-like methods return QuerySets and not Managers. def iterator(self, chunk_size: int = ...) -> Iterator[_T]: ... + async def aiterator(self, chunk_size: int = ...) -> Iterator[_T]: ... def aggregate(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: ... + async def aaggregate(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: ... def get(self, *args: Any, **kwargs: Any) -> _T: ... + async def aget(self, *args: Any, **kwargs: Any) -> _T: ... def create(self, **kwargs: Any) -> _T: ... + async def acreate(self, **kwargs: Any) -> _T: ... def bulk_create( self, objs: Iterable[_T], batch_size: Optional[int] = ..., ignore_conflicts: bool = ... ) -> List[_T]: ... + async def abulk_create( + self, objs: Iterable[_T], batch_size: Optional[int] = ..., ignore_conflicts: bool = ... + ) -> List[_T]: ... def bulk_update(self, objs: Iterable[_T], fields: Sequence[str], batch_size: Optional[int] = ...) -> int: ... + async def abulk_update(self, objs: Iterable[_T], fields: Sequence[str], batch_size: Optional[int] = ...) -> int: ... def get_or_create(self, defaults: Optional[MutableMapping[str, Any]] = ..., **kwargs: Any) -> Tuple[_T, bool]: ... + async def aget_or_create( + self, defaults: Optional[MutableMapping[str, Any]] = ..., **kwargs: Any + ) -> Tuple[_T, bool]: ... def update_or_create( self, defaults: Optional[MutableMapping[str, Any]] = ..., **kwargs: Any ) -> Tuple[_T, bool]: ... + async def aupdate_or_create( + self, defaults: Optional[MutableMapping[str, Any]] = ..., **kwargs: Any + ) -> Tuple[_T, bool]: ... def earliest(self, *fields: Any, field_name: Optional[Any] = ...) -> _T: ... + async def aearliest(self, *fields: Any, field_name: Optional[Any] = ...) -> _T: ... def latest(self, *fields: Any, field_name: Optional[Any] = ...) -> _T: ... + async def alatest(self, *fields: Any, field_name: Optional[Any] = ...) -> _T: ... def first(self) -> Optional[_T]: ... + async def afirst(self) -> Optional[_T]: ... def last(self) -> Optional[_T]: ... + async def alast(self) -> Optional[_T]: ... def in_bulk(self, id_list: Iterable[Any] = ..., *, field_name: str = ...) -> Dict[Any, _T]: ... + async def ain_bulk(self, id_list: Iterable[Any] = ..., *, field_name: str = ...) -> Dict[Any, _T]: ... def delete(self) -> Tuple[int, Dict[str, int]]: ... + async def adelete(self) -> Tuple[int, Dict[str, int]]: ... def update(self, **kwargs: Any) -> int: ... + async def aupdate(self, **kwargs: Any) -> int: ... def exists(self) -> bool: ... + async def aexists(self) -> bool: ... def explain(self, *, format: Optional[Any] = ..., **options: Any) -> str: ... + async def aexplain(self, *, format: Optional[Any] = ..., **options: Any) -> str: ... + def contains(self, objs: Iterable[_T]) -> bool: ... + async def acontains(self, objs: Iterable[_T]) -> bool: ... def raw( self, raw_query: str, @@ -93,6 +118,7 @@ class BaseManager(Generic[_T]): def exclude(self, *args: Any, **kwargs: Any) -> QuerySet[_T]: ... def complex_filter(self, filter_obj: Any) -> QuerySet[_T]: ... def count(self) -> int: ... + async def acount(self) -> int: ... def union(self, *other_qs: Any, all: bool = ...) -> QuerySet[_T]: ... def intersection(self, *other_qs: Any) -> QuerySet[_T]: ... def difference(self, *other_qs: Any) -> QuerySet[_T]: ... diff --git a/django-stubs/db/models/query.pyi b/django-stubs/db/models/query.pyi index 2ad08b1..4aadd58 100644 --- a/django-stubs/db/models/query.pyi +++ b/django-stubs/db/models/query.pyi @@ -57,25 +57,49 @@ class _QuerySet(Generic[_T, _Row], Collection[_Row], Reversible[_Row], Sized): # the corresponding method in BaseManager. def iterator(self, chunk_size: int = ...) -> Iterator[_Row]: ... def aggregate(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: ... + async def aaggregate(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: ... def get(self, *args: Any, **kwargs: Any) -> _Row: ... + async def aget(self, *args: Any, **kwargs: Any) -> _Row: ... def create(self, **kwargs: Any) -> _T: ... + async def acreate(self, **kwargs: Any) -> _T: ... def bulk_create( self, objs: Iterable[_T], batch_size: Optional[int] = ..., ignore_conflicts: bool = ... ) -> List[_T]: ... + async def abulk_create( + self, objs: Iterable[_T], batch_size: Optional[int] = ..., ignore_conflicts: bool = ... + ) -> List[_T]: ... def bulk_update(self, objs: Iterable[_T], fields: Iterable[str], batch_size: Optional[int] = ...) -> int: ... + async def abulk_update(self, objs: Iterable[_T], fields: Iterable[str], batch_size: Optional[int] = ...) -> int: ... def get_or_create(self, defaults: Optional[MutableMapping[str, Any]] = ..., **kwargs: Any) -> Tuple[_T, bool]: ... + async def aget_or_create( + self, defaults: Optional[MutableMapping[str, Any]] = ..., **kwargs: Any + ) -> Tuple[_T, bool]: ... def update_or_create( self, defaults: Optional[MutableMapping[str, Any]] = ..., **kwargs: Any ) -> Tuple[_T, bool]: ... + async def aupdate_or_create( + self, defaults: Optional[MutableMapping[str, Any]] = ..., **kwargs: Any + ) -> Tuple[_T, bool]: ... def earliest(self, *fields: Any, field_name: Optional[Any] = ...) -> _Row: ... + async def aearliest(self, *fields: Any, field_name: Optional[Any] = ...) -> _Row: ... def latest(self, *fields: Any, field_name: Optional[Any] = ...) -> _Row: ... + async def alatest(self, *fields: Any, field_name: Optional[Any] = ...) -> _Row: ... def first(self) -> Optional[_Row]: ... + async def afirst(self) -> Optional[_Row]: ... def last(self) -> Optional[_Row]: ... + async def alast(self) -> Optional[_Row]: ... def in_bulk(self, id_list: Iterable[Any] = ..., *, field_name: str = ...) -> Dict[Any, _T]: ... + async def ain_bulk(self, id_list: Iterable[Any] = ..., *, field_name: str = ...) -> Dict[Any, _T]: ... def delete(self) -> Tuple[int, Dict[str, int]]: ... + async def adelete(self) -> Tuple[int, Dict[str, int]]: ... def update(self, **kwargs: Any) -> int: ... + async def aupdate(self, **kwargs: Any) -> int: ... def exists(self) -> bool: ... + async def aexists(self) -> bool: ... def explain(self, *, format: Optional[Any] = ..., **options: Any) -> str: ... + async def aexplain(self, *, format: Optional[Any] = ..., **options: Any) -> str: ... + def contains(self, objs: Iterable[_T]) -> bool: ... + async def acontains(self, objs: Iterable[_T]) -> bool: ... def raw( self, raw_query: str, @@ -99,6 +123,7 @@ class _QuerySet(Generic[_T, _Row], Collection[_Row], Reversible[_Row], Sized): def exclude(self: _QS, *args: Any, **kwargs: Any) -> _QS: ... def complex_filter(self, filter_obj: Any) -> _QS: ... def count(self) -> int: ... + async def acount(self) -> int: ... def union(self: _QS, *other_qs: Any, all: bool = ...) -> _QS: ... def intersection(self: _QS, *other_qs: Any) -> _QS: ... def difference(self: _QS, *other_qs: Any) -> _QS: ... @@ -164,6 +189,7 @@ class RawQuerySet(Iterable[_T], Sized): @property def db(self) -> str: ... def iterator(self) -> Iterator[_T]: ... + async def aiterator(self) -> Iterator[_T]: ... @property def model_fields(self) -> Dict[str, str]: ... def prefetch_related(self, *lookups: Any) -> RawQuerySet[_T]: ...