mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-19 10:21:14 +08:00
add support for managers as generics
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import Type, Union, TypeVar, Any, Generic, List, Optional, Dict, Callable, Tuple, Sequence
|
||||
from typing import Type, Union, TypeVar, Any, Generic, List, Optional, Dict, Callable, Tuple, Sequence, TYPE_CHECKING
|
||||
from uuid import UUID
|
||||
|
||||
from django.db import models
|
||||
@@ -6,6 +6,9 @@ from django.db.models import Field, Model, QuerySet
|
||||
from django.db.models.fields.mixins import FieldCacheMixin
|
||||
from django.db.models.query_utils import PathInfo, Q
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.db.models.manager import RelatedManager
|
||||
|
||||
_T = TypeVar("_T", bound=models.Model)
|
||||
|
||||
class RelatedField(FieldCacheMixin, Field):
|
||||
@@ -64,7 +67,7 @@ class ManyToManyField(RelatedField, Generic[_T]):
|
||||
**kwargs: Any
|
||||
) -> None: ...
|
||||
def __set__(self, instance, value: Sequence[_T]) -> None: ...
|
||||
def __get__(self, instance, owner) -> QuerySet[_T]: ...
|
||||
def __get__(self, instance, owner) -> RelatedManager[_T]: ...
|
||||
def check(self, **kwargs: Any) -> List[Any]: ...
|
||||
def deconstruct(self) -> Tuple[Optional[str], str, List[Any], Dict[str, str]]: ...
|
||||
def get_path_info(self, filtered_relation: None = ...) -> List[PathInfo]: ...
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from typing import Any, Dict, List, Optional, Tuple, Type, Union, TypeVar, Set, Generic, Iterator
|
||||
from unittest.mock import MagicMock
|
||||
from typing import Any, Dict, List, Optional, Tuple, Type, TypeVar
|
||||
|
||||
from django.db.models import Q
|
||||
from django.db.models.base import Model
|
||||
from django.db.models.query import QuerySet, RawQuerySet
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
_T = TypeVar("_T", bound=Model)
|
||||
|
||||
class BaseManager:
|
||||
class BaseManager(QuerySet[_T]):
|
||||
creation_counter: int = ...
|
||||
auto_created: bool = ...
|
||||
use_in_migrations: bool = ...
|
||||
@@ -24,57 +19,13 @@ class BaseManager:
|
||||
def from_queryset(cls, queryset_class: Any, class_name: Optional[Any] = ...): ...
|
||||
def contribute_to_class(self, model: Type[Model], name: str) -> None: ...
|
||||
def db_manager(self, using: Optional[str] = ..., hints: Optional[Dict[str, Model]] = ...) -> Manager: ...
|
||||
@property
|
||||
def db(self) -> str: ...
|
||||
def get_queryset(self) -> QuerySet: ...
|
||||
def all(self) -> QuerySet: ...
|
||||
def __eq__(self, other: Optional[Any]) -> bool: ...
|
||||
def __hash__(self): ...
|
||||
def get_queryset(self) -> QuerySet[_T]: ...
|
||||
|
||||
class Manager(Generic[_T]):
|
||||
def exists(self) -> bool: ...
|
||||
def explain(self, *, format: Optional[Any] = ..., **options: Any) -> str: ...
|
||||
def raw(
|
||||
self,
|
||||
raw_query: str,
|
||||
params: Optional[Union[Dict[str, str], List[datetime], List[Decimal], List[str], Set[str], Tuple[int]]] = ...,
|
||||
translations: Optional[Dict[str, str]] = ...,
|
||||
using: None = ...,
|
||||
) -> RawQuerySet: ...
|
||||
def values(self, *fields: Any, **expressions: Any) -> QuerySet: ...
|
||||
def values_list(self, *fields: Any, flat: bool = ..., named: bool = ...) -> QuerySet: ...
|
||||
def dates(self, field_name: str, kind: str, order: str = ...) -> QuerySet: ...
|
||||
def datetimes(self, field_name: str, kind: str, order: str = ..., tzinfo: None = ...) -> QuerySet: ...
|
||||
def none(self) -> QuerySet[_T]: ...
|
||||
def all(self) -> QuerySet[_T]: ...
|
||||
def filter(self, *args: Any, **kwargs: Any) -> QuerySet[_T]: ...
|
||||
def exclude(self, *args: Any, **kwargs: Any) -> QuerySet[_T]: ...
|
||||
def complex_filter(
|
||||
self, filter_obj: Union[Dict[str, datetime], Dict[str, QuerySet], Q, MagicMock]
|
||||
) -> QuerySet[_T]: ...
|
||||
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]: ...
|
||||
def select_for_update(self, nowait: bool = ..., skip_locked: bool = ..., of: Tuple = ...) -> QuerySet: ...
|
||||
def select_related(self, *fields: Any) -> QuerySet[_T]: ...
|
||||
def prefetch_related(self, *lookups: Any) -> QuerySet[_T]: ...
|
||||
def annotate(self, *args: Any, **kwargs: Any) -> QuerySet[_T]: ...
|
||||
def order_by(self, *field_names: Any) -> QuerySet[_T]: ...
|
||||
def distinct(self, *field_names: Any) -> QuerySet[_T]: ...
|
||||
def extra(
|
||||
self,
|
||||
select: Optional[Union[Dict[str, int], Dict[str, str], OrderedDict]] = ...,
|
||||
where: Optional[List[str]] = ...,
|
||||
params: Optional[Union[List[int], List[str]]] = ...,
|
||||
tables: Optional[List[str]] = ...,
|
||||
order_by: Optional[Union[List[str], Tuple[str]]] = ...,
|
||||
select_params: Optional[Union[List[int], List[str], Tuple[int]]] = ...,
|
||||
) -> QuerySet[_T]: ...
|
||||
def iterator(self, chunk_size: int = ...) -> Iterator[_T]: ...
|
||||
def aggregate(self, *args: Any, **kwargs: Any) -> Dict[str, Optional[Union[datetime, float]]]: ...
|
||||
def count(self) -> int: ...
|
||||
def get(self, *args: Any, **kwargs: Any) -> _T: ...
|
||||
def create(self, **kwargs: Any) -> _T: ...
|
||||
class Manager(BaseManager[_T]): ...
|
||||
|
||||
class RelatedManager(Manager[_T]):
|
||||
def add(self, *objs: _T, bulk: bool = ...) -> None: ...
|
||||
def clear(self) -> None: ...
|
||||
|
||||
class ManagerDescriptor:
|
||||
manager: Manager = ...
|
||||
|
||||
@@ -1,23 +1,9 @@
|
||||
from collections import OrderedDict
|
||||
from datetime import date, datetime
|
||||
from typing import (
|
||||
TypeVar,
|
||||
Optional,
|
||||
Any,
|
||||
Type,
|
||||
Dict,
|
||||
Union,
|
||||
overload,
|
||||
List,
|
||||
Iterator,
|
||||
Tuple,
|
||||
Callable,
|
||||
Iterable,
|
||||
Sized,
|
||||
Reversible,
|
||||
)
|
||||
from typing import TypeVar, Optional, Any, Type, Dict, Union, overload, List, Iterator, Tuple, Callable, Iterable, Sized
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import Manager
|
||||
|
||||
_T = TypeVar("_T", bound=models.Model)
|
||||
|
||||
@@ -30,7 +16,7 @@ class QuerySet(Iterable[_T], Sized):
|
||||
hints: Optional[Dict[str, models.Model]] = ...,
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def as_manager(cls): ...
|
||||
def as_manager(cls) -> Manager[Any]: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __iter__(self) -> Iterator[_T]: ...
|
||||
def __bool__(self) -> bool: ...
|
||||
@@ -110,6 +96,8 @@ class QuerySet(Iterable[_T], Sized):
|
||||
@property
|
||||
def db(self) -> str: ...
|
||||
def resolve_expression(self, *args: Any, **kwargs: Any) -> Any: ...
|
||||
# TODO: remove when django adds __class_getitem__ methods
|
||||
def __getattr__(self, item: str) -> Any: ...
|
||||
|
||||
class RawQuerySet:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user