mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-15 08:17:08 +08:00
some stubs
This commit is contained in:
@@ -15,7 +15,7 @@ jobs:
|
|||||||
- name: "Lint with black"
|
- name: "Lint with black"
|
||||||
python: 3.7
|
python: 3.7
|
||||||
script: |
|
script: |
|
||||||
black --check --line-length=130 django-stubs/ django-stubs-generated/
|
black --check --line-length=120 django-stubs/ django-stubs-generated/
|
||||||
|
|
||||||
before_install: |
|
before_install: |
|
||||||
# Upgrade pip, setuptools, and wheel
|
# Upgrade pip, setuptools, and wheel
|
||||||
|
|||||||
@@ -21,4 +21,6 @@ def url(
|
|||||||
regex: str, view: Tuple[URLConf, Optional[str], Optional[str]], kwargs: Dict[str, Any] = None, name: str = None
|
regex: str, view: Tuple[URLConf, Optional[str], Optional[str]], kwargs: Dict[str, Any] = None, name: str = None
|
||||||
) -> RegexURLResolver: ...
|
) -> RegexURLResolver: ...
|
||||||
@overload
|
@overload
|
||||||
def url(regex: str, view: List[Union[URLConf, str]], kwargs: Dict[str, Any] = None, name: str = None) -> RegexURLResolver: ...
|
def url(
|
||||||
|
regex: str, view: List[Union[URLConf, str]], kwargs: Dict[str, Any] = None, name: str = None
|
||||||
|
) -> RegexURLResolver: ...
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Any, Dict, List, Optional, Tuple, Union, TypeVar, Generic
|
from typing import Any, Dict, List, Optional, Tuple, Union, TypeVar, Generic, Sequence
|
||||||
|
|
||||||
from django.db.models.fields import Field
|
from django.db.models.fields import Field
|
||||||
|
|
||||||
@@ -31,4 +31,5 @@ class ArrayField(CheckFieldDefaultMixin, Field, Generic[_T]):
|
|||||||
def validate(self, value: Any, model_instance: Any) -> None: ...
|
def validate(self, value: Any, model_instance: Any) -> None: ...
|
||||||
def run_validators(self, value: Any) -> None: ...
|
def run_validators(self, value: Any) -> None: ...
|
||||||
def formfield(self, **kwargs: Any): ...
|
def formfield(self, **kwargs: Any): ...
|
||||||
|
def __set__(self, instance, value: Sequence[_T]): ...
|
||||||
def __get__(self, instance, owner) -> List[_T]: ...
|
def __get__(self, instance, owner) -> List[_T]: ...
|
||||||
|
|||||||
@@ -1,27 +1,34 @@
|
|||||||
# Stubs for django.core.files.base (Python 3.5)
|
from io import StringIO
|
||||||
|
from typing import Any, Iterator, Optional, Union
|
||||||
|
|
||||||
from typing import Any, Iterable, Iterator, Optional, Sized, Union
|
|
||||||
from django.core.files.utils import FileProxyMixin
|
from django.core.files.utils import FileProxyMixin
|
||||||
|
|
||||||
class File(FileProxyMixin, Sized, Iterable[bytes]):
|
class File(FileProxyMixin):
|
||||||
DEFAULT_CHUNK_SIZE = ... # type: int
|
DEFAULT_CHUNK_SIZE: Any = ...
|
||||||
file = ... # type: Any
|
file: StringIO = ...
|
||||||
name: Optional[str] = ... # type: ignore
|
name: Optional[str] = ...
|
||||||
mode = ... # type: str
|
mode: str = ...
|
||||||
size = ... # type: int
|
def __init__(self, file: Any, name: Optional[str] = ...) -> None: ...
|
||||||
def __init__(self, file: Any, name: str = None) -> None: ...
|
def __bool__(self) -> bool: ...
|
||||||
@property
|
def __len__(self) -> int: ...
|
||||||
def closed(self) -> bool: ...
|
def size(self) -> int: ...
|
||||||
def chunks(self, chunk_size: int = None) -> Iterator[bytes]: ...
|
def chunks(self, chunk_size: Optional[int] = ...) -> Iterator[Union[bytes, bytearray]]: ...
|
||||||
def multiple_chunks(self, chunk_size: int = None) -> bool: ...
|
def multiple_chunks(self, chunk_size: Optional[Any] = ...): ...
|
||||||
def __enter__(self) -> "File": ...
|
def __iter__(self) -> Iterator[Union[bytes, str]]: ...
|
||||||
def __exit__(self, t: type = None, value: BaseException = None, traceback: Any = None) -> bool: ...
|
def __enter__(self) -> File: ...
|
||||||
def open(self, mode: str = None) -> None: ...
|
def __exit__(self, exc_type: None, exc_value: None, tb: None) -> None: ...
|
||||||
|
def open(self, mode: Optional[str] = ...) -> File: ...
|
||||||
def close(self) -> None: ...
|
def close(self) -> None: ...
|
||||||
|
|
||||||
class ContentFile(File):
|
class ContentFile(File):
|
||||||
def __init__(self, content: Union[str, bytes], name: Optional[str] = None) -> None: ...
|
file: StringIO
|
||||||
|
size: Any = ...
|
||||||
|
def __init__(self, content: Union[bytes, str], name: Optional[str] = ...) -> None: ...
|
||||||
|
def __bool__(self) -> bool: ...
|
||||||
|
def open(self, mode: Optional[str] = ...) -> ContentFile: ...
|
||||||
|
def close(self) -> None: ...
|
||||||
|
def write(self, data: str) -> int: ...
|
||||||
|
|
||||||
def endswith_cr(line: Union[str, bytes]) -> bool: ...
|
def endswith_cr(line: bytes) -> bool: ...
|
||||||
def endswith_lf(line: Union[str, bytes]) -> bool: ...
|
def endswith_lf(line: Union[bytes, str]) -> bool: ...
|
||||||
def equals_lf(line: Union[str, bytes]) -> bool: ...
|
def equals_lf(line: bytes) -> bool: ...
|
||||||
|
|||||||
@@ -1,7 +1,23 @@
|
|||||||
from typing import BinaryIO, Any, Optional, Tuple, Union
|
from typing import Any
|
||||||
|
|
||||||
class FileProxyMixin(BinaryIO):
|
class FileProxyMixin:
|
||||||
|
encoding: Any = ...
|
||||||
newlines = ... # type: Union[str, Tuple[str, ...], None]
|
fileno: Any = ...
|
||||||
softspace = ... # type: bool
|
flush: Any = ...
|
||||||
def readinto(self, b: Any) -> Optional[int]: ...
|
isatty: Any = ...
|
||||||
|
newlines: Any = ...
|
||||||
|
read: Any = ...
|
||||||
|
readinto: Any = ...
|
||||||
|
readline: Any = ...
|
||||||
|
readlines: Any = ...
|
||||||
|
seek: Any = ...
|
||||||
|
tell: Any = ...
|
||||||
|
truncate: Any = ...
|
||||||
|
write: Any = ...
|
||||||
|
writelines: Any = ...
|
||||||
|
@property
|
||||||
|
def closed(self) -> bool: ...
|
||||||
|
def readable(self) -> bool: ...
|
||||||
|
def writable(self) -> bool: ...
|
||||||
|
def seekable(self) -> bool: ...
|
||||||
|
def __iter__(self): ...
|
||||||
|
|||||||
@@ -23,10 +23,23 @@ from .deletion import CASCADE as CASCADE, SET_DEFAULT as SET_DEFAULT, SET_NULL a
|
|||||||
|
|
||||||
from .query import QuerySet as QuerySet, RawQuerySet as RawQuerySet
|
from .query import QuerySet as QuerySet, RawQuerySet as RawQuerySet
|
||||||
|
|
||||||
from .query_utils import Q as Q
|
from .query_utils import Q as Q, FilteredRelation as FilteredRelation
|
||||||
|
|
||||||
from .lookups import Lookup as Lookup
|
from .lookups import Lookup as Lookup
|
||||||
|
|
||||||
from .expressions import F as F, Subquery as Subquery, Exists as Exists, OrderBy as OrderBy, OuterRef as OuterRef
|
from .expressions import (
|
||||||
|
F as F,
|
||||||
|
Expression as Expression,
|
||||||
|
Subquery as Subquery,
|
||||||
|
Exists as Exists,
|
||||||
|
OrderBy as OrderBy,
|
||||||
|
OuterRef as OuterRef,
|
||||||
|
Case as Case,
|
||||||
|
When as When,
|
||||||
|
RawSQL as RawSQL,
|
||||||
|
Value as Value,
|
||||||
|
)
|
||||||
|
|
||||||
from .manager import BaseManager as BaseManager, Manager as Manager
|
from .manager import BaseManager as BaseManager, Manager as Manager
|
||||||
|
|
||||||
|
from .aggregates import Count as Count, Aggregate as Aggregate
|
||||||
|
|||||||
51
django-stubs/db/models/aggregates.pyi
Normal file
51
django-stubs/db/models/aggregates.pyi
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
from typing import Any, Optional
|
||||||
|
|
||||||
|
from django.db.models.expressions import Func
|
||||||
|
from django.db.models.query_utils import Q
|
||||||
|
|
||||||
|
class Aggregate(Func):
|
||||||
|
name: Any = ...
|
||||||
|
filter_template: str = ...
|
||||||
|
window_compatible: bool = ...
|
||||||
|
filter: Any = ...
|
||||||
|
def __init__(self, *args: Any, filter: Optional[Any] = ..., **kwargs: Any) -> None: ...
|
||||||
|
|
||||||
|
class Avg(Aggregate):
|
||||||
|
filter: None
|
||||||
|
function: str = ...
|
||||||
|
name: str = ...
|
||||||
|
|
||||||
|
class Count(Aggregate):
|
||||||
|
filter: None
|
||||||
|
function: str = ...
|
||||||
|
name: str = ...
|
||||||
|
template: str = ...
|
||||||
|
output_field: Any = ...
|
||||||
|
def __init__(self, expression: str, distinct: bool = ..., filter: Optional[Q] = ..., **extra: Any) -> None: ...
|
||||||
|
|
||||||
|
class Max(Aggregate):
|
||||||
|
filter: None
|
||||||
|
function: str = ...
|
||||||
|
name: str = ...
|
||||||
|
|
||||||
|
class Min(Aggregate):
|
||||||
|
filter: None
|
||||||
|
function: str = ...
|
||||||
|
name: str = ...
|
||||||
|
|
||||||
|
class StdDev(Aggregate):
|
||||||
|
filter: None
|
||||||
|
name: str = ...
|
||||||
|
output_field: Any = ...
|
||||||
|
function: str = ...
|
||||||
|
|
||||||
|
class Sum(Aggregate):
|
||||||
|
filter: None
|
||||||
|
function: str = ...
|
||||||
|
name: str = ...
|
||||||
|
|
||||||
|
class Variance(Aggregate):
|
||||||
|
filter: None
|
||||||
|
name: str = ...
|
||||||
|
output_field: Any = ...
|
||||||
|
function: str = ...
|
||||||
@@ -5,6 +5,7 @@ from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Ty
|
|||||||
from django.db.models import QuerySet
|
from django.db.models import QuerySet
|
||||||
from django.db.models.fields import Field
|
from django.db.models.fields import Field
|
||||||
from django.db.models.lookups import Lookup
|
from django.db.models.lookups import Lookup
|
||||||
|
from django.db.models.sql import Query
|
||||||
from django.db.models.sql.compiler import SQLCompiler
|
from django.db.models.sql.compiler import SQLCompiler
|
||||||
|
|
||||||
class SQLiteNumericMixin:
|
class SQLiteNumericMixin:
|
||||||
@@ -136,3 +137,49 @@ class OrderBy(BaseExpression):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self, expression: Combinable, descending: bool = ..., nulls_first: bool = ..., nulls_last: bool = ...
|
self, expression: Combinable, descending: bool = ..., nulls_first: bool = ..., nulls_last: bool = ...
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
|
class Value(Expression):
|
||||||
|
value: Any = ...
|
||||||
|
def __init__(self, value: Any, output_field: Optional[Field] = ...) -> None: ...
|
||||||
|
|
||||||
|
class RawSQL(Expression):
|
||||||
|
output_field: Field
|
||||||
|
params: List[Any]
|
||||||
|
sql: str
|
||||||
|
def __init__(self, sql: str, params: Union[List[int], List[str], Tuple], output_field: None = ...) -> None: ...
|
||||||
|
|
||||||
|
class Func(SQLiteNumericMixin, Expression):
|
||||||
|
function: Any = ...
|
||||||
|
template: str = ...
|
||||||
|
arg_joiner: str = ...
|
||||||
|
arity: Any = ...
|
||||||
|
source_expressions: Any = ...
|
||||||
|
extra: Any = ...
|
||||||
|
def __init__(self, *expressions: Any, output_field: Optional[Any] = ..., **extra: Any) -> None: ...
|
||||||
|
def get_source_expressions(self) -> List[Combinable]: ...
|
||||||
|
def set_source_expressions(self, exprs: List[Expression]) -> None: ...
|
||||||
|
def resolve_expression(
|
||||||
|
self,
|
||||||
|
query: Query = ...,
|
||||||
|
allow_joins: bool = ...,
|
||||||
|
reuse: Optional[Set[Any]] = ...,
|
||||||
|
summarize: bool = ...,
|
||||||
|
for_save: bool = ...,
|
||||||
|
) -> Func: ...
|
||||||
|
def copy(self) -> Func: ...
|
||||||
|
|
||||||
|
class When(Expression):
|
||||||
|
template: str = ...
|
||||||
|
condition: Any = ...
|
||||||
|
result: Any = ...
|
||||||
|
def __init__(self, condition: Any = ..., then: Any = ..., **lookups: Any) -> None: ...
|
||||||
|
|
||||||
|
class Case(Expression):
|
||||||
|
template: str = ...
|
||||||
|
case_joiner: str = ...
|
||||||
|
cases: Any = ...
|
||||||
|
default: Any = ...
|
||||||
|
extra: Any = ...
|
||||||
|
def __init__(
|
||||||
|
self, *cases: Any, default: Optional[Any] = ..., output_field: Optional[Any] = ..., **extra: Any
|
||||||
|
) -> None: ...
|
||||||
|
|||||||
@@ -17,14 +17,17 @@ class AutoField(Field):
|
|||||||
|
|
||||||
class CharField(Field):
|
class CharField(Field):
|
||||||
def __init__(self, max_length: int, **kwargs): ...
|
def __init__(self, max_length: int, **kwargs): ...
|
||||||
|
def __set__(self, instance, value: str) -> None: ...
|
||||||
def __get__(self, instance, owner) -> str: ...
|
def __get__(self, instance, owner) -> str: ...
|
||||||
|
|
||||||
class SlugField(CharField): ...
|
class SlugField(CharField): ...
|
||||||
|
|
||||||
class TextField(Field):
|
class TextField(Field):
|
||||||
|
def __set__(self, instance, value: str) -> None: ...
|
||||||
def __get__(self, instance, owner) -> str: ...
|
def __get__(self, instance, owner) -> str: ...
|
||||||
|
|
||||||
class BooleanField(Field):
|
class BooleanField(Field):
|
||||||
|
def __set__(self, instance, value: bool) -> None: ...
|
||||||
def __get__(self, instance, owner) -> bool: ...
|
def __get__(self, instance, owner) -> bool: ...
|
||||||
|
|
||||||
class FileField(Field): ...
|
class FileField(Field): ...
|
||||||
|
|||||||
12
django-stubs/db/models/fields/mixins.pyi
Normal file
12
django-stubs/db/models/fields/mixins.pyi
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from typing import Any, Optional
|
||||||
|
|
||||||
|
from django.db.models.base import Model
|
||||||
|
|
||||||
|
NOT_PROVIDED: Any
|
||||||
|
|
||||||
|
class FieldCacheMixin:
|
||||||
|
def get_cache_name(self) -> None: ...
|
||||||
|
def get_cached_value(self, instance: Model, default: Any = ...) -> Optional[Model]: ...
|
||||||
|
def is_cached(self, instance: Model) -> bool: ...
|
||||||
|
def set_cached_value(self, instance: Model, value: Optional[Model]) -> None: ...
|
||||||
|
def delete_cached_value(self, instance: Model) -> None: ...
|
||||||
@@ -1,18 +1,82 @@
|
|||||||
from typing import Type, Union, TypeVar, Any, Generic
|
from typing import Type, Union, TypeVar, Any, Generic, List, Optional, Dict, Callable, Tuple, Sequence
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Field
|
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
|
||||||
|
|
||||||
_T = TypeVar("_T", bound=models.Model)
|
_T = TypeVar("_T", bound=models.Model)
|
||||||
|
|
||||||
class ForeignKey(Field, Generic[_T]):
|
class RelatedField(FieldCacheMixin, Field):
|
||||||
|
one_to_many: bool = ...
|
||||||
|
one_to_one: bool = ...
|
||||||
|
many_to_many: bool = ...
|
||||||
|
many_to_one: bool = ...
|
||||||
|
def related_model(self) -> Union[Type[Model], str]: ...
|
||||||
|
def check(self, **kwargs: Any) -> List[Any]: ...
|
||||||
|
opts: Any = ...
|
||||||
|
def deconstruct(self) -> Tuple[Optional[str], str, List[Any], Dict[str, str]]: ...
|
||||||
|
def get_forward_related_filter(self, obj: Model) -> Dict[str, Union[int, UUID]]: ...
|
||||||
|
def get_reverse_related_filter(self, obj: Model) -> Q: ...
|
||||||
|
@property
|
||||||
|
def swappable_setting(self) -> Optional[str]: ...
|
||||||
|
name: Any = ...
|
||||||
|
verbose_name: Any = ...
|
||||||
|
def set_attributes_from_rel(self) -> None: ...
|
||||||
|
def do_related_class(self, other: Type[Model], cls: Type[Model]) -> None: ...
|
||||||
|
def get_limit_choices_to(self) -> Dict[str, int]: ...
|
||||||
|
def formfield(self, **kwargs: Any) -> Field: ...
|
||||||
|
def related_query_name(self) -> str: ...
|
||||||
|
@property
|
||||||
|
def target_field(self) -> Field: ...
|
||||||
|
|
||||||
|
class ForeignKey(RelatedField, Generic[_T]):
|
||||||
def __init__(self, to: Union[Type[_T], str], on_delete: Any, related_name: str = ..., **kwargs): ...
|
def __init__(self, to: Union[Type[_T], str], on_delete: Any, related_name: str = ..., **kwargs): ...
|
||||||
def __get__(self, instance, owner) -> _T: ...
|
def __get__(self, instance, owner) -> _T: ...
|
||||||
|
|
||||||
class OneToOneField(Field, Generic[_T]):
|
class OneToOneField(RelatedField, Generic[_T]):
|
||||||
def __init__(self, to: Union[Type[_T], str], on_delete: Any, related_name: str = ..., **kwargs): ...
|
def __init__(self, to: Union[Type[_T], str], on_delete: Any, related_name: str = ..., **kwargs): ...
|
||||||
def __get__(self, instance, owner) -> _T: ...
|
def __get__(self, instance, owner) -> _T: ...
|
||||||
|
|
||||||
class ManyToManyField(Field, Generic[_T]):
|
class ManyToManyField(RelatedField, Generic[_T]):
|
||||||
def __init__(self, to: Union[Type[_T], str], on_delete: Any, related_name: str = ..., **kwargs): ...
|
many_to_many: bool = ...
|
||||||
def __get__(self, instance, owner) -> _T: ...
|
many_to_one: bool = ...
|
||||||
|
one_to_many: bool = ...
|
||||||
|
one_to_one: bool = ...
|
||||||
|
rel_class: Any = ...
|
||||||
|
description: Any = ...
|
||||||
|
has_null_arg: Any = ...
|
||||||
|
db_table: Any = ...
|
||||||
|
swappable: Any = ...
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
to: Union[Type[_T], str],
|
||||||
|
related_name: Optional[str] = ...,
|
||||||
|
related_query_name: Optional[str] = ...,
|
||||||
|
limit_choices_to: Optional[Callable] = ...,
|
||||||
|
symmetrical: Optional[bool] = ...,
|
||||||
|
through: Optional[str] = ...,
|
||||||
|
through_fields: Optional[Tuple[str, str]] = ...,
|
||||||
|
db_constraint: bool = ...,
|
||||||
|
db_table: None = ...,
|
||||||
|
swappable: bool = ...,
|
||||||
|
**kwargs: Any
|
||||||
|
) -> None: ...
|
||||||
|
def __set__(self, instance, value: Sequence[_T]) -> None: ...
|
||||||
|
def __get__(self, instance, owner) -> QuerySet[_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]: ...
|
||||||
|
def get_reverse_path_info(self, filtered_relation: None = ...) -> List[PathInfo]: ...
|
||||||
|
m2m_db_table: Any = ...
|
||||||
|
m2m_column_name: Any = ...
|
||||||
|
m2m_reverse_name: Any = ...
|
||||||
|
m2m_field_name: Any = ...
|
||||||
|
m2m_reverse_field_name: Any = ...
|
||||||
|
m2m_target_field_name: Any = ...
|
||||||
|
m2m_reverse_target_field_name: Any = ...
|
||||||
|
def contribute_to_related_class(self, cls: Type[Model], related: RelatedField) -> None: ...
|
||||||
|
def set_attributes_from_rel(self) -> None: ...
|
||||||
|
def value_from_object(self, obj: Model) -> List[Model]: ...
|
||||||
|
def save_form_data(self, instance: Model, data: QuerySet) -> None: ...
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ class Manager(Generic[_T]):
|
|||||||
def all(self) -> QuerySet[_T]: ...
|
def all(self) -> QuerySet[_T]: ...
|
||||||
def filter(self, *args: Any, **kwargs: Any) -> QuerySet[_T]: ...
|
def filter(self, *args: Any, **kwargs: Any) -> QuerySet[_T]: ...
|
||||||
def exclude(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 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 union(self, *other_qs: Any, all: bool = ...) -> QuerySet[_T]: ...
|
||||||
def intersection(self, *other_qs: Any) -> QuerySet[_T]: ...
|
def intersection(self, *other_qs: Any) -> QuerySet[_T]: ...
|
||||||
def difference(self, *other_qs: Any) -> QuerySet[_T]: ...
|
def difference(self, *other_qs: Any) -> QuerySet[_T]: ...
|
||||||
|
|||||||
@@ -1,12 +1,26 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from typing import Generic, TypeVar, Optional, Any, Type, Dict, Union, overload, List, Iterator, Tuple, Callable
|
from typing import (
|
||||||
|
Generic,
|
||||||
|
TypeVar,
|
||||||
|
Optional,
|
||||||
|
Any,
|
||||||
|
Type,
|
||||||
|
Dict,
|
||||||
|
Union,
|
||||||
|
overload,
|
||||||
|
List,
|
||||||
|
Iterator,
|
||||||
|
Tuple,
|
||||||
|
Callable,
|
||||||
|
Sequence,
|
||||||
|
)
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
_T = TypeVar("_T", bound=models.Model)
|
_T = TypeVar("_T", bound=models.Model)
|
||||||
|
|
||||||
class QuerySet(Generic[_T]):
|
class QuerySet(Sequence[_T]):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
model: Optional[Type[models.Model]] = ...,
|
model: Optional[Type[models.Model]] = ...,
|
||||||
@@ -20,19 +34,20 @@ class QuerySet(Generic[_T]):
|
|||||||
def __iter__(self) -> Iterator[_T]: ...
|
def __iter__(self) -> Iterator[_T]: ...
|
||||||
def __bool__(self) -> bool: ...
|
def __bool__(self) -> bool: ...
|
||||||
@overload
|
@overload
|
||||||
def __getitem__(self, k: slice) -> QuerySet[_T]: ...
|
|
||||||
@overload
|
|
||||||
def __getitem__(self, k: int) -> _T: ...
|
def __getitem__(self, k: int) -> _T: ...
|
||||||
@overload
|
@overload
|
||||||
def __getitem__(self, k: str) -> Any: ...
|
def __getitem__(self, k: str) -> Any: ...
|
||||||
|
@overload
|
||||||
|
def __getitem__(self, k: slice) -> QuerySet[_T]: ...
|
||||||
def __and__(self, other: QuerySet) -> QuerySet: ...
|
def __and__(self, other: QuerySet) -> QuerySet: ...
|
||||||
def __or__(self, other: QuerySet) -> QuerySet: ...
|
def __or__(self, other: QuerySet) -> QuerySet: ...
|
||||||
def iterator(self, chunk_size: int = ...) -> Iterator[_T]: ...
|
def iterator(self, chunk_size: int = ...) -> Iterator[_T]: ...
|
||||||
def aggregate(self, *args: Any, **kwargs: Any) -> Dict[str, Optional[Union[datetime, float]]]: ...
|
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 get(self, *args: Any, **kwargs: Any) -> _T: ...
|
||||||
def create(self, **kwargs: Any) -> _T: ...
|
def create(self, **kwargs: Any) -> _T: ...
|
||||||
def bulk_create(self, objs: Union[Iterator[Any], List[models.Model]], batch_size: Optional[int] = ...) -> List[_T]: ...
|
def bulk_create(
|
||||||
|
self, objs: Union[Iterator[Any], List[models.Model]], batch_size: Optional[int] = ...
|
||||||
|
) -> List[_T]: ...
|
||||||
def get_or_create(
|
def get_or_create(
|
||||||
self, defaults: Optional[Union[Dict[str, date], Dict[str, models.Model]]] = ..., **kwargs: Any
|
self, defaults: Optional[Union[Dict[str, date], Dict[str, models.Model]]] = ..., **kwargs: Any
|
||||||
) -> Tuple[_T, bool]: ...
|
) -> Tuple[_T, bool]: ...
|
||||||
@@ -43,7 +58,7 @@ class QuerySet(Generic[_T]):
|
|||||||
) -> Tuple[_T, bool]: ...
|
) -> Tuple[_T, bool]: ...
|
||||||
def earliest(self, *fields: Any, field_name: Optional[Any] = ...) -> _T: ...
|
def earliest(self, *fields: Any, field_name: Optional[Any] = ...) -> _T: ...
|
||||||
def latest(self, *fields: Any, field_name: Optional[Any] = ...) -> _T: ...
|
def latest(self, *fields: Any, field_name: Optional[Any] = ...) -> _T: ...
|
||||||
def first(self) -> Optional[Union[Dict[str, int], _T]]: ...
|
def first(self) -> Optional[_T]: ...
|
||||||
def last(self) -> Optional[_T]: ...
|
def last(self) -> Optional[_T]: ...
|
||||||
def in_bulk(
|
def in_bulk(
|
||||||
self, id_list: Any = ..., *, field_name: str = ...
|
self, id_list: Any = ..., *, field_name: str = ...
|
||||||
@@ -56,7 +71,7 @@ class QuerySet(Generic[_T]):
|
|||||||
self, raw_query: str, params: Any = ..., translations: Optional[Dict[str, str]] = ..., using: None = ...
|
self, raw_query: str, params: Any = ..., translations: Optional[Dict[str, str]] = ..., using: None = ...
|
||||||
) -> RawQuerySet: ...
|
) -> RawQuerySet: ...
|
||||||
def values(self, *fields: Any, **expressions: Any) -> QuerySet: ...
|
def values(self, *fields: Any, **expressions: Any) -> QuerySet: ...
|
||||||
def values_list(self, *fields: Any, flat: bool = ..., named: bool = ...) -> QuerySet: ...
|
def values_list(self, *fields: Any, flat: bool = ..., named: bool = ...) -> List[Any]: ...
|
||||||
def dates(self, field_name: str, kind: str, order: str = ...) -> 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 datetimes(self, field_name: str, kind: str, order: str = ..., tzinfo: None = ...) -> QuerySet: ...
|
||||||
def none(self) -> QuerySet[_T]: ...
|
def none(self) -> QuerySet[_T]: ...
|
||||||
|
|||||||
@@ -1,8 +1,84 @@
|
|||||||
class RegisterLookupMixin:
|
from collections import OrderedDict, namedtuple
|
||||||
pass
|
from typing import Any, Dict, Iterator, List, Optional, Set, Tuple, Type, Union
|
||||||
|
|
||||||
class Q(object):
|
from django.db.models.base import Model
|
||||||
def __init__(self, *args, **kwargs) -> None: ...
|
from django.db.models.expressions import Expression
|
||||||
def __or__(self, other: Q) -> Q: ...
|
from django.db.models.fields import Field
|
||||||
def __and__(self, other: Q) -> Q: ...
|
from django.db.models.fields.mixins import FieldCacheMixin
|
||||||
|
from django.db.models.sql.compiler import SQLCompiler
|
||||||
|
from django.db.models.sql.query import Query
|
||||||
|
from django.db.models.sql.where import WhereNode
|
||||||
|
from django.utils import tree
|
||||||
|
|
||||||
|
PathInfo = namedtuple("PathInfo", "from_opts to_opts target_fields join_field m2m direct filtered_relation")
|
||||||
|
|
||||||
|
class InvalidQuery(Exception): ...
|
||||||
|
|
||||||
|
def subclasses(cls: Type[RegisterLookupMixin]) -> Iterator[Type[RegisterLookupMixin]]: ...
|
||||||
|
|
||||||
|
class QueryWrapper:
|
||||||
|
contains_aggregate: bool = ...
|
||||||
|
data: Tuple[str, List[Any]] = ...
|
||||||
|
def __init__(self, sql: str, params: List[Any]) -> None: ...
|
||||||
|
def as_sql(self, compiler: SQLCompiler = ..., connection: Any = ...) -> Tuple[str, List[Any]]: ...
|
||||||
|
|
||||||
|
class Q(tree.Node):
|
||||||
|
children: Union[List[Dict[str, str]], List[Tuple[str, Any]], List[Q]]
|
||||||
|
connector: str
|
||||||
|
negated: bool
|
||||||
|
AND: str = ...
|
||||||
|
OR: str = ...
|
||||||
|
default: Any = ...
|
||||||
|
conditional: bool = ...
|
||||||
|
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||||
|
def __or__(self, other: Any) -> Q: ...
|
||||||
|
def __and__(self, other: Any) -> Q: ...
|
||||||
def __invert__(self) -> Q: ...
|
def __invert__(self) -> Q: ...
|
||||||
|
def resolve_expression(
|
||||||
|
self,
|
||||||
|
query: Query = ...,
|
||||||
|
allow_joins: bool = ...,
|
||||||
|
reuse: Optional[Set[str]] = ...,
|
||||||
|
summarize: bool = ...,
|
||||||
|
for_save: bool = ...,
|
||||||
|
) -> WhereNode: ...
|
||||||
|
def deconstruct(self) -> Tuple[str, Tuple, Dict[str, str]]: ...
|
||||||
|
|
||||||
|
class DeferredAttribute:
|
||||||
|
field_name: str = ...
|
||||||
|
def __init__(self, field_name: str) -> None: ...
|
||||||
|
def __get__(self, instance: Optional[Model], cls: Type[Model] = ...) -> Any: ...
|
||||||
|
|
||||||
|
class RegisterLookupMixin:
|
||||||
|
@classmethod
|
||||||
|
def get_lookups(cls) -> Dict[str, Any]: ...
|
||||||
|
def get_lookup(self, lookup_name: str) -> Optional[Any]: ...
|
||||||
|
def get_transform(self, lookup_name: str) -> Optional[Any]: ...
|
||||||
|
@staticmethod
|
||||||
|
def merge_dicts(dicts: List[Dict[str, Any]]) -> Dict[str, Any]: ...
|
||||||
|
@classmethod
|
||||||
|
def register_lookup(cls, lookup: Any, lookup_name: Optional[str] = ...) -> Type[Any]: ...
|
||||||
|
|
||||||
|
def select_related_descend(
|
||||||
|
field: Field,
|
||||||
|
restricted: bool,
|
||||||
|
requested: Optional[
|
||||||
|
Union[Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, Dict[Any, Any]]]]]]]], bool]
|
||||||
|
],
|
||||||
|
load_fields: Optional[Set[str]],
|
||||||
|
reverse: bool = ...,
|
||||||
|
) -> bool: ...
|
||||||
|
def refs_expression(
|
||||||
|
lookup_parts: List[str], annotations: OrderedDict
|
||||||
|
) -> Union[Tuple[bool, Tuple], Tuple[Expression, List[str]]]: ...
|
||||||
|
def check_rel_lookup_compatibility(model: Type[Model], target_opts: Any, field: FieldCacheMixin) -> bool: ...
|
||||||
|
|
||||||
|
class FilteredRelation:
|
||||||
|
relation_name: str = ...
|
||||||
|
alias: Optional[str] = ...
|
||||||
|
condition: Q = ...
|
||||||
|
path: List[str] = ...
|
||||||
|
def __init__(self, relation_name: str, *, condition: Any = ...) -> None: ...
|
||||||
|
def clone(self) -> FilteredRelation: ...
|
||||||
|
def resolve_expression(self, *args: Any, **kwargs: Any) -> None: ...
|
||||||
|
def as_sql(self, compiler: SQLCompiler, connection: Any) -> Tuple[str, List[Union[int, str]]]: ...
|
||||||
|
|||||||
@@ -35,11 +35,15 @@ class SQLCompiler:
|
|||||||
select: List[Tuple[BaseExpression, Tuple[str, List[float]], Optional[str]]],
|
select: List[Tuple[BaseExpression, Tuple[str, List[float]], Optional[str]]],
|
||||||
order_by: List[Tuple[Expression, Tuple[str, List[Union[int, str]], bool]]],
|
order_by: List[Tuple[Expression, Tuple[str, List[Union[int, str]], bool]]],
|
||||||
) -> List[Tuple[str, List[float]]]: ...
|
) -> List[Tuple[str, List[float]]]: ...
|
||||||
def collapse_group_by(self, expressions: List[Expression], having: Union[List[Expression], Tuple]) -> List[Expression]: ...
|
def collapse_group_by(
|
||||||
|
self, expressions: List[Expression], having: Union[List[Expression], Tuple]
|
||||||
|
) -> List[Expression]: ...
|
||||||
def get_select(
|
def get_select(
|
||||||
self
|
self
|
||||||
) -> Tuple[
|
) -> Tuple[
|
||||||
List[Tuple[Expression, Tuple[str, List[Union[int, str]]], Optional[str]]], Optional[Dict[str, Any]], Dict[str, int]
|
List[Tuple[Expression, Tuple[str, List[Union[int, str]]], Optional[str]]],
|
||||||
|
Optional[Dict[str, Any]],
|
||||||
|
Dict[str, int],
|
||||||
]: ...
|
]: ...
|
||||||
def get_order_by(self) -> List[Tuple[Expression, Tuple[str, List[Any], bool]]]: ...
|
def get_order_by(self) -> List[Tuple[Expression, Tuple[str, List[Any], bool]]]: ...
|
||||||
def get_extra_select(
|
def get_extra_select(
|
||||||
@@ -48,7 +52,9 @@ class SQLCompiler:
|
|||||||
select: List[Tuple[Expression, Tuple[str, List[float]], Optional[str]]],
|
select: List[Tuple[Expression, Tuple[str, List[float]], Optional[str]]],
|
||||||
) -> List[Tuple[Expression, Tuple[str, List[Any]], None]]: ...
|
) -> List[Tuple[Expression, Tuple[str, List[Any]], None]]: ...
|
||||||
def quote_name_unless_alias(self, name: str) -> str: ...
|
def quote_name_unless_alias(self, name: str) -> str: ...
|
||||||
def compile(self, node: Any, select_format: Any = ...) -> Tuple[str, Union[List[Optional[int]], Tuple[int, int]]]: ...
|
def compile(
|
||||||
|
self, node: Any, select_format: Any = ...
|
||||||
|
) -> Tuple[str, Union[List[Optional[int]], Tuple[int, int]]]: ...
|
||||||
def get_combinator_sql(self, combinator: str, all: bool) -> Tuple[List[str], Union[List[int], List[str]]]: ...
|
def get_combinator_sql(self, combinator: str, all: bool) -> Tuple[List[str], Union[List[int], List[str]]]: ...
|
||||||
def as_sql(self, with_limits: bool = ..., with_col_aliases: bool = ...) -> Any: ...
|
def as_sql(self, with_limits: bool = ..., with_col_aliases: bool = ...) -> Any: ...
|
||||||
def get_default_columns(
|
def get_default_columns(
|
||||||
@@ -93,6 +99,8 @@ class SQLCompiler:
|
|||||||
chunk_size: int = ...,
|
chunk_size: int = ...,
|
||||||
) -> Iterator[Any]: ...
|
) -> Iterator[Any]: ...
|
||||||
def has_results(self) -> bool: ...
|
def has_results(self) -> bool: ...
|
||||||
def execute_sql(self, result_type: str = ..., chunked_fetch: bool = ..., chunk_size: int = ...) -> Optional[Any]: ...
|
def execute_sql(
|
||||||
|
self, result_type: str = ..., chunked_fetch: bool = ..., chunk_size: int = ...
|
||||||
|
) -> Optional[Any]: ...
|
||||||
def as_subquery_condition(self, alias: str, columns: List[str], compiler: SQLCompiler) -> Tuple[str, Tuple]: ...
|
def as_subquery_condition(self, alias: str, columns: List[str], compiler: SQLCompiler) -> Tuple[str, Tuple]: ...
|
||||||
def explain_query(self) -> Iterator[str]: ...
|
def explain_query(self) -> Iterator[str]: ...
|
||||||
|
|||||||
50
django-stubs/db/models/sql/datastructures.pyi
Normal file
50
django-stubs/db/models/sql/datastructures.pyi
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
from collections import OrderedDict
|
||||||
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||||
|
|
||||||
|
from django.db.models.fields.mixins import FieldCacheMixin
|
||||||
|
from django.db.models.query_utils import FilteredRelation, PathInfo
|
||||||
|
from django.db.models.sql.compiler import SQLCompiler
|
||||||
|
|
||||||
|
class MultiJoin(Exception):
|
||||||
|
level: int = ...
|
||||||
|
names_with_path: List[Tuple[str, List[PathInfo]]] = ...
|
||||||
|
def __init__(self, names_pos: int, path_with_names: List[Tuple[str, List[PathInfo]]]) -> None: ...
|
||||||
|
|
||||||
|
class Empty: ...
|
||||||
|
|
||||||
|
class Join:
|
||||||
|
table_name: str = ...
|
||||||
|
parent_alias: str = ...
|
||||||
|
table_alias: Optional[str] = ...
|
||||||
|
join_type: str = ...
|
||||||
|
join_cols: Tuple = ...
|
||||||
|
join_field: FieldCacheMixin = ...
|
||||||
|
nullable: bool = ...
|
||||||
|
filtered_relation: Optional[FilteredRelation] = ...
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
table_name: str,
|
||||||
|
parent_alias: str,
|
||||||
|
table_alias: Optional[str],
|
||||||
|
join_type: str,
|
||||||
|
join_field: FieldCacheMixin,
|
||||||
|
nullable: bool,
|
||||||
|
filtered_relation: Optional[FilteredRelation] = ...,
|
||||||
|
) -> None: ...
|
||||||
|
def as_sql(self, compiler: SQLCompiler, connection: Any) -> Tuple[str, List[Union[int, str]]]: ...
|
||||||
|
def relabeled_clone(self, change_map: Union[Dict[str, str], OrderedDict]) -> Join: ...
|
||||||
|
def equals(self, other: Union[BaseTable, Join], with_filtered_relation: bool) -> bool: ...
|
||||||
|
def __eq__(self, other: Union[BaseTable, Join]) -> bool: ...
|
||||||
|
def demote(self) -> Join: ...
|
||||||
|
def promote(self) -> Join: ...
|
||||||
|
|
||||||
|
class BaseTable:
|
||||||
|
join_type: Any = ...
|
||||||
|
parent_alias: Any = ...
|
||||||
|
filtered_relation: Any = ...
|
||||||
|
table_name: str = ...
|
||||||
|
table_alias: Optional[str] = ...
|
||||||
|
def __init__(self, table_name: str, alias: Optional[str]) -> None: ...
|
||||||
|
def as_sql(self, compiler: SQLCompiler, connection: Any) -> Tuple[str, List[Any]]: ...
|
||||||
|
def relabeled_clone(self, change_map: OrderedDict) -> BaseTable: ...
|
||||||
|
def equals(self, other: Join, with_filtered_relation: bool) -> bool: ...
|
||||||
187
django-stubs/db/models/sql/query.pyi
Normal file
187
django-stubs/db/models/sql/query.pyi
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
import collections
|
||||||
|
from collections import OrderedDict, namedtuple
|
||||||
|
from datetime import datetime
|
||||||
|
from decimal import Decimal
|
||||||
|
from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from django.db.models import Model, Field, Q, FilteredRelation, Expression, QuerySet
|
||||||
|
from django.db.models.query_utils import PathInfo
|
||||||
|
from django.db.models.sql.compiler import SQLCompiler
|
||||||
|
from django.db.models.sql.where import WhereNode
|
||||||
|
|
||||||
|
JoinInfo = namedtuple("JoinInfo", ["final_field", "targets", "opts", "joins", "path", "transform_function"])
|
||||||
|
|
||||||
|
class RawQuery:
|
||||||
|
high_mark: None
|
||||||
|
low_mark: int
|
||||||
|
params: Union[Any] = ...
|
||||||
|
sql: str = ...
|
||||||
|
using: str = ...
|
||||||
|
extra_select: Dict[Any, Any] = ...
|
||||||
|
annotation_select: Dict[Any, Any] = ...
|
||||||
|
def __init__(self, sql: str, using: str, params: Any = ...) -> None: ...
|
||||||
|
def chain(self, using: str) -> RawQuery: ...
|
||||||
|
def clone(self, using: str) -> RawQuery: ...
|
||||||
|
def get_columns(self) -> List[str]: ...
|
||||||
|
def __iter__(self): ...
|
||||||
|
|
||||||
|
class Query:
|
||||||
|
base_table: str
|
||||||
|
related_ids: None
|
||||||
|
related_updates: Dict[Type[Model], List[Tuple[Field, None, Union[int, str]]]]
|
||||||
|
values: List[Any]
|
||||||
|
alias_prefix: str = ...
|
||||||
|
subq_aliases: frozenset = ...
|
||||||
|
compiler: str = ...
|
||||||
|
model: Optional[Type[Model]] = ...
|
||||||
|
alias_refcount: Dict[str, int] = ...
|
||||||
|
alias_map: OrderedDict = ...
|
||||||
|
external_aliases: Set[str] = ...
|
||||||
|
table_map: Dict[str, List[str]] = ...
|
||||||
|
default_cols: bool = ...
|
||||||
|
default_ordering: bool = ...
|
||||||
|
standard_ordering: bool = ...
|
||||||
|
used_aliases: Set[str] = ...
|
||||||
|
filter_is_sticky: bool = ...
|
||||||
|
subquery: bool = ...
|
||||||
|
order_by: Tuple = ...
|
||||||
|
distinct: bool = ...
|
||||||
|
distinct_fields: Tuple = ...
|
||||||
|
select_for_update: bool = ...
|
||||||
|
select_for_update_nowait: bool = ...
|
||||||
|
select_for_update_skip_locked: bool = ...
|
||||||
|
select_for_update_of: Tuple = ...
|
||||||
|
select_related: Union[
|
||||||
|
Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, Dict[Any, Any]]]]]]]], bool
|
||||||
|
] = ...
|
||||||
|
max_depth: int = ...
|
||||||
|
values_select: Tuple = ...
|
||||||
|
annotation_select_mask: Optional[Set[str]] = ...
|
||||||
|
combinator: Optional[str] = ...
|
||||||
|
combinator_all: bool = ...
|
||||||
|
combined_queries: Tuple = ...
|
||||||
|
extra_select_mask: Optional[Set[str]] = ...
|
||||||
|
extra_tables: Tuple = ...
|
||||||
|
extra_order_by: Union[List[str], Tuple] = ...
|
||||||
|
deferred_loading: Tuple[Union[Set[str], frozenset], bool] = ...
|
||||||
|
explain_query: bool = ...
|
||||||
|
explain_format: Optional[str] = ...
|
||||||
|
explain_options: Dict[str, int] = ...
|
||||||
|
def __init__(self, model: Optional[Type[Model]], where: Type[WhereNode] = ...) -> None: ...
|
||||||
|
@property
|
||||||
|
def extra(self) -> OrderedDict: ...
|
||||||
|
@property
|
||||||
|
def annotations(self) -> OrderedDict: ...
|
||||||
|
@property
|
||||||
|
def has_select_fields(self) -> bool: ...
|
||||||
|
def sql_with_params(self) -> Tuple[str, Tuple]: ...
|
||||||
|
def __deepcopy__(self, memo: Dict[str, Any]) -> Query: ...
|
||||||
|
def get_compiler(self, using: Optional[str] = ..., connection: Any = ...) -> SQLCompiler: ...
|
||||||
|
def clone(self) -> Query: ...
|
||||||
|
def chain(self, klass: Optional[Type[Query]] = ...) -> Query: ...
|
||||||
|
def relabeled_clone(self, change_map: Union[Dict[Any, Any], OrderedDict]) -> Query: ...
|
||||||
|
def get_count(self, using: str) -> int: ...
|
||||||
|
def has_filters(self) -> WhereNode: ...
|
||||||
|
def has_results(self, using: str) -> bool: ...
|
||||||
|
def explain(self, using: str, format: Optional[str] = ..., **options: Any) -> str: ...
|
||||||
|
def combine(self, rhs: Query, connector: str) -> None: ...
|
||||||
|
def deferred_to_data(self, target: Dict[Any, Any], callback: Callable) -> None: ...
|
||||||
|
def ref_alias(self, alias: str) -> None: ...
|
||||||
|
def unref_alias(self, alias: str, amount: int = ...) -> None: ...
|
||||||
|
def promote_joins(self, aliases: Set[str]) -> None: ...
|
||||||
|
def demote_joins(self, aliases: Set[str]) -> None: ...
|
||||||
|
def reset_refcounts(self, to_counts: Dict[str, int]) -> None: ...
|
||||||
|
def change_aliases(self, change_map: Union[Dict[Any, Any], OrderedDict]) -> None: ...
|
||||||
|
def bump_prefix(self, outer_query: Query) -> None: ...
|
||||||
|
def get_initial_alias(self) -> str: ...
|
||||||
|
def count_active_tables(self) -> int: ...
|
||||||
|
def resolve_expression(self, query: Query, *args: Any, **kwargs: Any) -> Query: ...
|
||||||
|
def as_sql(self, compiler: SQLCompiler, connection: Any) -> Tuple[str, Tuple]: ...
|
||||||
|
def resolve_lookup_value(self, value: Any, can_reuse: Optional[Set[str]], allow_joins: bool) -> Any: ...
|
||||||
|
def build_filter(
|
||||||
|
self,
|
||||||
|
filter_expr: Union[Dict[str, str], Tuple[str, Tuple[int, int]]],
|
||||||
|
branch_negated: bool = ...,
|
||||||
|
current_negated: bool = ...,
|
||||||
|
can_reuse: Optional[Set[str]] = ...,
|
||||||
|
allow_joins: bool = ...,
|
||||||
|
split_subq: bool = ...,
|
||||||
|
reuse_with_filtered_relation: bool = ...,
|
||||||
|
) -> Tuple[WhereNode, List[Any]]: ...
|
||||||
|
def add_filter(self, filter_clause: Tuple[str, Union[List[int], List[str]]]) -> None: ...
|
||||||
|
def add_q(self, q_object: Q) -> None: ...
|
||||||
|
def build_filtered_relation_q(
|
||||||
|
self, q_object: Q, reuse: Set[str], branch_negated: bool = ..., current_negated: bool = ...
|
||||||
|
) -> WhereNode: ...
|
||||||
|
def add_filtered_relation(self, filtered_relation: FilteredRelation, alias: str) -> None: ...
|
||||||
|
def setup_joins(
|
||||||
|
self,
|
||||||
|
names: List[str],
|
||||||
|
opts: Any,
|
||||||
|
alias: str,
|
||||||
|
can_reuse: Optional[Set[str]] = ...,
|
||||||
|
allow_many: bool = ...,
|
||||||
|
reuse_with_filtered_relation: bool = ...,
|
||||||
|
) -> JoinInfo: ...
|
||||||
|
def trim_joins(
|
||||||
|
self, targets: Tuple[Field], joins: List[str], path: List[PathInfo]
|
||||||
|
) -> Tuple[Tuple[Field], str, List[str]]: ...
|
||||||
|
def resolve_ref(
|
||||||
|
self, name: str, allow_joins: bool = ..., reuse: Optional[Set[str]] = ..., summarize: bool = ...
|
||||||
|
) -> Expression: ...
|
||||||
|
def split_exclude(
|
||||||
|
self,
|
||||||
|
filter_expr: Tuple[str, Union[QuerySet, int]],
|
||||||
|
can_reuse: Set[str],
|
||||||
|
names_with_path: List[Tuple[str, List[PathInfo]]],
|
||||||
|
) -> Tuple[WhereNode, Tuple]: ...
|
||||||
|
def set_empty(self) -> None: ...
|
||||||
|
def is_empty(self) -> bool: ...
|
||||||
|
high_mark: Optional[int] = ...
|
||||||
|
low_mark: int = ...
|
||||||
|
def set_limits(self, low: Optional[int] = ..., high: Optional[int] = ...) -> None: ...
|
||||||
|
def clear_limits(self) -> None: ...
|
||||||
|
def has_limit_one(self) -> bool: ...
|
||||||
|
def can_filter(self) -> bool: ...
|
||||||
|
def clear_select_clause(self) -> None: ...
|
||||||
|
def clear_select_fields(self) -> None: ...
|
||||||
|
def set_select(self, cols: List[Expression]) -> None: ...
|
||||||
|
def add_distinct_fields(self, *field_names: Any) -> None: ...
|
||||||
|
def add_fields(self, field_names: Union[Iterator[Any], List[str]], allow_m2m: bool = ...) -> None: ...
|
||||||
|
def add_ordering(self, *ordering: Any) -> None: ...
|
||||||
|
def clear_ordering(self, force_empty: bool) -> None: ...
|
||||||
|
def set_group_by(self) -> None: ...
|
||||||
|
def add_select_related(self, fields: Tuple[str]) -> None: ...
|
||||||
|
def add_extra(
|
||||||
|
self,
|
||||||
|
select: Optional[Union[Dict[str, int], Dict[str, str], OrderedDict]],
|
||||||
|
select_params: Optional[Union[List[int], List[str], Tuple[int]]],
|
||||||
|
where: Optional[List[str]],
|
||||||
|
params: Optional[List[str]],
|
||||||
|
tables: Optional[List[str]],
|
||||||
|
order_by: Optional[Union[List[str], Tuple[str]]],
|
||||||
|
) -> None: ...
|
||||||
|
def clear_deferred_loading(self) -> None: ...
|
||||||
|
def add_deferred_loading(self, field_names: Tuple[str]) -> None: ...
|
||||||
|
def add_immediate_loading(self, field_names: Tuple[str]) -> None: ...
|
||||||
|
def get_loaded_field_names(self) -> Dict[Type[Model], Set[str]]: ...
|
||||||
|
def get_loaded_field_names_cb(
|
||||||
|
self, target: Dict[Type[Model], Set[str]], model: Type[Model], fields: Set[Field]
|
||||||
|
) -> None: ...
|
||||||
|
def set_annotation_mask(self, names: Optional[Union[List[str], Set[str], Tuple]]) -> None: ...
|
||||||
|
def append_annotation_mask(self, names: List[str]) -> None: ...
|
||||||
|
def set_extra_mask(self, names: Union[List[str], Tuple]) -> None: ...
|
||||||
|
def set_values(self, fields: Union[List[str], Tuple]) -> None: ...
|
||||||
|
def trim_start(self, names_with_path: List[Tuple[str, List[PathInfo]]]) -> Tuple[str, bool]: ...
|
||||||
|
def is_nullable(self, field: Field) -> bool: ...
|
||||||
|
|
||||||
|
class JoinPromoter:
|
||||||
|
connector: str = ...
|
||||||
|
negated: bool = ...
|
||||||
|
effective_connector: str = ...
|
||||||
|
num_children: int = ...
|
||||||
|
votes: collections.Counter = ...
|
||||||
|
def __init__(self, connector: str, num_children: int, negated: bool) -> None: ...
|
||||||
|
def add_votes(self, votes: Union[Iterator[Any], List[Any], Set[str], Tuple]) -> None: ...
|
||||||
|
def update_join_types(self, query: Query) -> Set[str]: ...
|
||||||
211
django-stubs/db/models/sql/subqueries.pyi
Normal file
211
django-stubs/db/models/sql/subqueries.pyi
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
||||||
|
|
||||||
|
from django.db.models.base import Model
|
||||||
|
from django.db.models.expressions import Case
|
||||||
|
from django.db.models.fields import DateTimeCheckMixin, Field
|
||||||
|
from django.db.models.query import QuerySet
|
||||||
|
from django.db.models.sql.query import Query
|
||||||
|
from django.db.models.sql.where import WhereNode
|
||||||
|
from django.utils.datastructures import ImmutableList
|
||||||
|
|
||||||
|
class DeleteQuery(Query):
|
||||||
|
alias_refcount: Dict[str, int]
|
||||||
|
annotation_select_mask: None
|
||||||
|
base_table: str
|
||||||
|
combinator: None
|
||||||
|
combinator_all: bool
|
||||||
|
combined_queries: Tuple
|
||||||
|
default_cols: bool
|
||||||
|
default_ordering: bool
|
||||||
|
deferred_loading: Tuple[frozenset, bool]
|
||||||
|
distinct: bool
|
||||||
|
distinct_fields: Tuple
|
||||||
|
explain_format: None
|
||||||
|
explain_options: Dict[Any, Any]
|
||||||
|
explain_query: bool
|
||||||
|
external_aliases: Set[Any]
|
||||||
|
extra_order_by: Tuple
|
||||||
|
extra_select_mask: None
|
||||||
|
extra_tables: Tuple
|
||||||
|
filter_is_sticky: bool
|
||||||
|
group_by: None
|
||||||
|
high_mark: None
|
||||||
|
low_mark: int
|
||||||
|
max_depth: int
|
||||||
|
model: Type[django.db.models.base.Model]
|
||||||
|
order_by: Tuple
|
||||||
|
select: Tuple
|
||||||
|
select_for_update: bool
|
||||||
|
select_for_update_nowait: bool
|
||||||
|
select_for_update_of: Tuple
|
||||||
|
select_for_update_skip_locked: bool
|
||||||
|
select_related: bool
|
||||||
|
standard_ordering: bool
|
||||||
|
subq_aliases: frozenset
|
||||||
|
subquery: bool
|
||||||
|
table_map: Dict[str, List[str]]
|
||||||
|
used_aliases: Set[str]
|
||||||
|
values_select: Tuple
|
||||||
|
where_class: Type[django.db.models.sql.where.WhereNode]
|
||||||
|
compiler: str = ...
|
||||||
|
alias_map: Union[Dict[str, django.db.models.sql.datastructures.BaseTable], collections.OrderedDict] = ...
|
||||||
|
where: django.db.models.sql.where.WhereNode = ...
|
||||||
|
def do_query(self, table: str, where: WhereNode, using: str) -> int: ...
|
||||||
|
def delete_batch(self, pk_list: Union[List[int], List[str]], using: str) -> int: ...
|
||||||
|
def delete_qs(self, query: QuerySet, using: str) -> int: ...
|
||||||
|
|
||||||
|
class UpdateQuery(Query):
|
||||||
|
alias_map: collections.OrderedDict
|
||||||
|
alias_refcount: Dict[str, int]
|
||||||
|
annotation_select_mask: Optional[Set[Any]]
|
||||||
|
base_table: str
|
||||||
|
combinator: None
|
||||||
|
combinator_all: bool
|
||||||
|
combined_queries: Tuple
|
||||||
|
default_cols: bool
|
||||||
|
default_ordering: bool
|
||||||
|
deferred_loading: Tuple[frozenset, bool]
|
||||||
|
distinct: bool
|
||||||
|
distinct_fields: Tuple
|
||||||
|
explain_format: None
|
||||||
|
explain_options: Dict[Any, Any]
|
||||||
|
explain_query: bool
|
||||||
|
external_aliases: Set[Any]
|
||||||
|
extra_order_by: Tuple
|
||||||
|
extra_select_mask: Optional[Set[Any]]
|
||||||
|
extra_tables: Tuple
|
||||||
|
filter_is_sticky: bool
|
||||||
|
group_by: Optional[bool]
|
||||||
|
high_mark: None
|
||||||
|
low_mark: int
|
||||||
|
max_depth: int
|
||||||
|
model: Type[django.db.models.base.Model]
|
||||||
|
order_by: Tuple
|
||||||
|
related_ids: Optional[List[int]]
|
||||||
|
related_updates: Dict[
|
||||||
|
Type[django.db.models.base.Model], List[Tuple[django.db.models.fields.Field, None, Union[int, str]]]
|
||||||
|
]
|
||||||
|
select: Tuple
|
||||||
|
select_for_update: bool
|
||||||
|
select_for_update_nowait: bool
|
||||||
|
select_for_update_of: Tuple
|
||||||
|
select_for_update_skip_locked: bool
|
||||||
|
select_related: bool
|
||||||
|
standard_ordering: bool
|
||||||
|
subq_aliases: frozenset
|
||||||
|
subquery: bool
|
||||||
|
table_map: Dict[str, List[str]]
|
||||||
|
used_aliases: Set[str]
|
||||||
|
values: List[
|
||||||
|
Tuple[
|
||||||
|
django.db.models.fields.Field,
|
||||||
|
Optional[Type[django.db.models.base.Model]],
|
||||||
|
Union[django.db.models.expressions.Case, uuid.UUID],
|
||||||
|
]
|
||||||
|
]
|
||||||
|
values_select: Tuple
|
||||||
|
where_class: Type[django.db.models.sql.where.WhereNode]
|
||||||
|
compiler: str = ...
|
||||||
|
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||||
|
def clone(self) -> UpdateQuery: ...
|
||||||
|
where: django.db.models.sql.where.WhereNode = ...
|
||||||
|
def update_batch(self, pk_list: List[int], values: Dict[str, Optional[int]], using: str) -> None: ...
|
||||||
|
def add_update_values(self, values: Dict[str, Any]) -> None: ...
|
||||||
|
def add_update_fields(self, values_seq: List[Tuple[Field, Optional[Type[Model]], Case]]) -> None: ...
|
||||||
|
def add_related_update(self, model: Type[Model], field: Field, value: Union[int, str]) -> None: ...
|
||||||
|
def get_related_updates(self) -> List[UpdateQuery]: ...
|
||||||
|
|
||||||
|
class InsertQuery(Query):
|
||||||
|
alias_map: collections.OrderedDict
|
||||||
|
alias_refcount: Dict[str, int]
|
||||||
|
annotation_select_mask: None
|
||||||
|
combinator: None
|
||||||
|
combinator_all: bool
|
||||||
|
combined_queries: Tuple
|
||||||
|
default_cols: bool
|
||||||
|
default_ordering: bool
|
||||||
|
deferred_loading: Tuple[frozenset, bool]
|
||||||
|
distinct: bool
|
||||||
|
distinct_fields: Tuple
|
||||||
|
explain_format: None
|
||||||
|
explain_options: Dict[Any, Any]
|
||||||
|
explain_query: bool
|
||||||
|
external_aliases: Set[Any]
|
||||||
|
extra_order_by: Tuple
|
||||||
|
extra_select_mask: None
|
||||||
|
extra_tables: Tuple
|
||||||
|
filter_is_sticky: bool
|
||||||
|
group_by: None
|
||||||
|
high_mark: None
|
||||||
|
low_mark: int
|
||||||
|
max_depth: int
|
||||||
|
model: Type[django.db.models.base.Model]
|
||||||
|
order_by: Tuple
|
||||||
|
select: Tuple
|
||||||
|
select_for_update: bool
|
||||||
|
select_for_update_nowait: bool
|
||||||
|
select_for_update_of: Tuple
|
||||||
|
select_for_update_skip_locked: bool
|
||||||
|
select_related: bool
|
||||||
|
standard_ordering: bool
|
||||||
|
subquery: bool
|
||||||
|
table_map: Dict[str, List[str]]
|
||||||
|
used_aliases: Set[Any]
|
||||||
|
values_select: Tuple
|
||||||
|
where: django.db.models.sql.where.WhereNode
|
||||||
|
where_class: Type[django.db.models.sql.where.WhereNode]
|
||||||
|
compiler: str = ...
|
||||||
|
fields: Union[
|
||||||
|
List[django.db.models.fields.DateTimeCheckMixin],
|
||||||
|
List[django.db.models.fields.Field],
|
||||||
|
django.utils.datastructures.ImmutableList,
|
||||||
|
] = ...
|
||||||
|
objs: List[django.db.models.base.Model] = ...
|
||||||
|
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
||||||
|
raw: bool = ...
|
||||||
|
def insert_values(
|
||||||
|
self, fields: Union[List[DateTimeCheckMixin], List[Field], ImmutableList], objs: List[Model], raw: bool = ...
|
||||||
|
) -> None: ...
|
||||||
|
|
||||||
|
class AggregateQuery(Query):
|
||||||
|
alias_map: collections.OrderedDict
|
||||||
|
alias_refcount: Dict[Any, Any]
|
||||||
|
annotation_select_mask: None
|
||||||
|
combinator: None
|
||||||
|
combinator_all: bool
|
||||||
|
combined_queries: Tuple
|
||||||
|
default_cols: bool
|
||||||
|
default_ordering: bool
|
||||||
|
deferred_loading: Tuple[frozenset, bool]
|
||||||
|
distinct: bool
|
||||||
|
distinct_fields: Tuple
|
||||||
|
explain_format: None
|
||||||
|
explain_options: Dict[Any, Any]
|
||||||
|
explain_query: bool
|
||||||
|
external_aliases: Set[Any]
|
||||||
|
extra_order_by: Tuple
|
||||||
|
extra_select_mask: None
|
||||||
|
extra_tables: Tuple
|
||||||
|
filter_is_sticky: bool
|
||||||
|
group_by: None
|
||||||
|
high_mark: None
|
||||||
|
low_mark: int
|
||||||
|
max_depth: int
|
||||||
|
model: Type[django.db.models.base.Model]
|
||||||
|
order_by: Tuple
|
||||||
|
select: Tuple
|
||||||
|
select_for_update: bool
|
||||||
|
select_for_update_nowait: bool
|
||||||
|
select_for_update_of: Tuple
|
||||||
|
select_for_update_skip_locked: bool
|
||||||
|
select_related: bool
|
||||||
|
standard_ordering: bool
|
||||||
|
sub_params: Tuple
|
||||||
|
subquery: Union[bool, str]
|
||||||
|
table_map: Dict[Any, Any]
|
||||||
|
used_aliases: Set[Any]
|
||||||
|
values_select: Tuple
|
||||||
|
where: django.db.models.sql.where.WhereNode
|
||||||
|
where_class: Type[django.db.models.sql.where.WhereNode]
|
||||||
|
compiler: str = ...
|
||||||
|
def add_subquery(self, query: Query, using: str) -> None: ...
|
||||||
46
django-stubs/db/models/sql/where.pyi
Normal file
46
django-stubs/db/models/sql/where.pyi
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
from collections import OrderedDict
|
||||||
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||||
|
|
||||||
|
from django.db.models.expressions import Expression
|
||||||
|
from django.db.models.sql.compiler import SQLCompiler
|
||||||
|
from django.db.models.sql.query import Query
|
||||||
|
from django.utils import tree
|
||||||
|
|
||||||
|
AND: str
|
||||||
|
OR: str
|
||||||
|
|
||||||
|
class WhereNode(tree.Node):
|
||||||
|
connector: str
|
||||||
|
contains_aggregate: bool
|
||||||
|
contains_over_clause: bool
|
||||||
|
negated: bool
|
||||||
|
default: Any = ...
|
||||||
|
resolved: bool = ...
|
||||||
|
conditional: bool = ...
|
||||||
|
def split_having(self, negated: bool = ...) -> Tuple[Optional[WhereNode], Optional[WhereNode]]: ...
|
||||||
|
def as_sql(self, compiler: SQLCompiler, connection: Any) -> Tuple[str, List[Union[int, str]]]: ...
|
||||||
|
def get_group_by_cols(self) -> List[Expression]: ...
|
||||||
|
def relabel_aliases(self, change_map: Union[Dict[Optional[str], str], OrderedDict]) -> None: ...
|
||||||
|
def clone(self) -> WhereNode: ...
|
||||||
|
def relabeled_clone(self, change_map: Union[Dict[Optional[str], str], OrderedDict]) -> WhereNode: ...
|
||||||
|
def resolve_expression(self, *args: Any, **kwargs: Any) -> WhereNode: ...
|
||||||
|
|
||||||
|
class NothingNode:
|
||||||
|
contains_aggregate: bool = ...
|
||||||
|
def as_sql(self, compiler: SQLCompiler = ..., connection: Any = ...) -> Any: ...
|
||||||
|
|
||||||
|
class ExtraWhere:
|
||||||
|
contains_aggregate: bool = ...
|
||||||
|
sqls: List[str] = ...
|
||||||
|
params: Optional[Union[List[int], List[str]]] = ...
|
||||||
|
def __init__(self, sqls: List[str], params: Optional[Union[List[int], List[str]]]) -> None: ...
|
||||||
|
def as_sql(self, compiler: SQLCompiler = ..., connection: Any = ...) -> Tuple[str, Union[List[int], List[str]]]: ...
|
||||||
|
|
||||||
|
class SubqueryConstraint:
|
||||||
|
contains_aggregate: bool = ...
|
||||||
|
alias: str = ...
|
||||||
|
columns: List[str] = ...
|
||||||
|
targets: List[str] = ...
|
||||||
|
query_object: Query = ...
|
||||||
|
def __init__(self, alias: str, columns: List[str], targets: List[str], query_object: Query) -> None: ...
|
||||||
|
def as_sql(self, compiler: SQLCompiler, connection: Any) -> Tuple[str, Tuple]: ...
|
||||||
@@ -15,7 +15,9 @@ class HttpResponseBase(six.Iterator):
|
|||||||
closed = ... # type: bool
|
closed = ... # type: bool
|
||||||
reason_phrase = ... # type: str
|
reason_phrase = ... # type: str
|
||||||
charset = ... # type: str
|
charset = ... # type: str
|
||||||
def __init__(self, content_type: str = None, status: int = None, reason: str = None, charset: str = None) -> None: ...
|
def __init__(
|
||||||
|
self, content_type: str = None, status: int = None, reason: str = None, charset: str = None
|
||||||
|
) -> None: ...
|
||||||
def serialize_headers(self) -> bytes: ...
|
def serialize_headers(self) -> bytes: ...
|
||||||
def __bytes__(self) -> bytes: ...
|
def __bytes__(self) -> bytes: ...
|
||||||
def __setitem__(self, header: str, value: Union[str, bytes]) -> None: ...
|
def __setitem__(self, header: str, value: Union[str, bytes]) -> None: ...
|
||||||
|
|||||||
14
django-stubs/utils/tree.pyi
Normal file
14
django-stubs/utils/tree.pyi
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from typing import Any, Dict, Optional, Tuple
|
||||||
|
|
||||||
|
class Node:
|
||||||
|
default: str = ...
|
||||||
|
connector: str = ...
|
||||||
|
negated: bool = ...
|
||||||
|
def __init__(self, children: Optional[Node] = ..., connector: Optional[str] = ..., negated: bool = ...) -> None: ...
|
||||||
|
def __deepcopy__(self, memodict: Dict[Any, Any]) -> Node: ...
|
||||||
|
def __len__(self) -> int: ...
|
||||||
|
def __bool__(self) -> bool: ...
|
||||||
|
def __contains__(self, other: Tuple[str, int]) -> bool: ...
|
||||||
|
def __hash__(self) -> int: ...
|
||||||
|
def add(self, data: Any, conn_type: str, squash: bool = ...) -> Any: ...
|
||||||
|
def negate(self) -> None: ...
|
||||||
@@ -16,7 +16,9 @@ class View:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def as_view(cls: Any, **initkwargs: object) -> Callable[..., http.HttpResponse]: ...
|
def as_view(cls: Any, **initkwargs: object) -> Callable[..., http.HttpResponse]: ...
|
||||||
def dispatch(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ...
|
def dispatch(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ...
|
||||||
def http_method_not_allowed(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ...
|
def http_method_not_allowed(
|
||||||
|
self, request: http.HttpRequest, *args: object, **kwargs: object
|
||||||
|
) -> http.HttpResponse: ...
|
||||||
def options(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ...
|
def options(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ...
|
||||||
|
|
||||||
class TemplateResponseMixin:
|
class TemplateResponseMixin:
|
||||||
|
|||||||
Reference in New Issue
Block a user