This commit is contained in:
Maxim Kurnikov
2018-08-14 12:09:47 +03:00
parent a13d4c352a
commit ca5f489092
3 changed files with 368 additions and 464 deletions

View File

@@ -8,6 +8,7 @@ from django.core.validators import DecimalValidator
from django.db.backends.sqlite3.base import DatabaseWrapper
from django.db.models.base import Model
from django.db.models.expressions import Col, CombinedExpression
from django.db.models.fields import reverse_related
from django.db.models.fields.files import FieldFile
from django.db.models.fields.reverse_related import ForeignObjectRel
from django.db.models.query import QuerySet

View File

@@ -1,3 +1,5 @@
import decimal
import operator
from collections import OrderedDict
from datetime import date, datetime
from decimal import Decimal
@@ -11,8 +13,6 @@ from django.contrib.contenttypes.fields import GenericForeignKey
from django.db.models.base import Model, ModelState
from django.db.models.expressions import Expression
from django.db.models.fields import Field
from django.db.models.fields.mixins import FieldCacheMixin
from django.db.models.fields.related import ForeignKey
from django.db.models.fields.related_descriptors import (ForwardManyToOneDescriptor,
ReverseOneToOneDescriptor)
from django.db.models.query_utils import Q
@@ -21,10 +21,12 @@ from django.db.models.sql.query import Query, RawQuery
REPR_OUTPUT_SIZE: int
EmptyResultSet: Any
class BaseIterable:
queryset: Any = ...
chunked_fetch: Any = ...
chunk_size: Any = ...
def __init__(
self,
queryset: QuerySet,
@@ -32,41 +34,54 @@ class BaseIterable:
chunk_size: int = ...,
) -> None: ...
class ModelIterable(BaseIterable):
chunk_size: int
chunked_fetch: bool
queryset: django.db.models.query.QuerySet
def __iter__(self) -> Iterator[Model]: ...
class ValuesIterable(BaseIterable):
chunk_size: int
chunked_fetch: bool
queryset: django.db.models.query.QuerySet
def __iter__(self) -> Iterator[Dict[str, Optional[Union[int, str]]]]: ...
class ValuesListIterable(BaseIterable):
chunk_size: int
chunked_fetch: bool
queryset: django.db.models.query.QuerySet
def __iter__(self) -> Union[chain, map]: ...
class NamedValuesListIterable(ValuesListIterable):
chunk_size: int
chunked_fetch: bool
queryset: django.db.models.query.QuerySet
queryset: QuerySet
@staticmethod
def create_namedtuple_class(*names: Any) -> Any: ...
def __iter__(self) -> Any: ...
class FlatValuesListIterable(BaseIterable):
chunk_size: int
chunked_fetch: bool
queryset: django.db.models.query.QuerySet
queryset: QuerySet
def __iter__(self) -> Iterator[Any]: ...
class QuerySet:
model: Optional[Type[django.db.models.base.Model]] = ...
query: django.db.models.sql.query.Query = ...
def __init__(
self,
model: Optional[Type[Model]] = ...,
@@ -74,8 +89,11 @@ class QuerySet:
using: Optional[str] = ...,
hints: Optional[Dict[str, Model]] = ...,
) -> None: ...
def as_manager(cls): ...
as_manager: Any = ...
def __deepcopy__(
self,
memo: Dict[
@@ -88,17 +106,27 @@ class QuerySet:
],
],
) -> QuerySet: ...
def __len__(self) -> int: ...
def __iter__(self) -> Any: ...
def __bool__(self) -> bool: ...
def __getitem__(self, k: Union[int, slice, str]) -> Any: ...
def __and__(self, other: QuerySet) -> QuerySet: ...
def __or__(self, other: QuerySet) -> QuerySet: ...
def iterator(self, chunk_size: int = ...) -> Iterator[Any]: ...
def aggregate(
self, *args: Any, **kwargs: Any
) -> Dict[str, Optional[Union[datetime, float]]]: ...
def count(self) -> int: ...
def get(
self, *args: Any, **kwargs: Any
) -> Union[
@@ -107,17 +135,21 @@ class QuerySet:
Model,
str,
]: ...
def create(self, **kwargs: Any) -> Model: ...
def bulk_create(
self,
objs: Union[Iterator[Any], List[Model]],
batch_size: Optional[int] = ...,
) -> List[Model]: ...
def get_or_create(
self,
defaults: Optional[Union[Dict[str, date], Dict[str, Model]]] = ...,
**kwargs: Any
) -> Tuple[Model, bool]: ...
def update_or_create(
self,
defaults: Optional[
@@ -130,23 +162,33 @@ class QuerySet:
] = ...,
**kwargs: Any
) -> Tuple[Model, bool]: ...
def earliest(
self, *fields: Any, field_name: Optional[Any] = ...
) -> Model: ...
def latest(
self, *fields: Any, field_name: Optional[Any] = ...
) -> Model: ...
def first(self) -> Optional[Union[Dict[str, int], Model]]: ...
def last(self) -> Optional[Model]: ...
def in_bulk(
self, id_list: Any = ..., *, field_name: str = ...
) -> Union[Dict[int, Model], Dict[str, Model]]: ...
def delete(self) -> Tuple[int, Dict[str, int]]: ...
def update(self, **kwargs: Any) -> int: ...
def exists(self) -> bool: ...
def explain(
self, *, format: Optional[Any] = ..., **options: Any
) -> str: ...
def raw(
self,
raw_query: str,
@@ -163,37 +205,56 @@ class QuerySet:
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: ...
def all(self) -> QuerySet: ...
def filter(self, *args: Any, **kwargs: Any) -> QuerySet: ...
def exclude(self, *args: Any, **kwargs: Any) -> QuerySet: ...
def complex_filter(
self,
filter_obj: Union[
Dict[str, datetime], Dict[str, QuerySet], Q, MagicMock
],
) -> QuerySet: ...
def union(self, *other_qs: Any, all: bool = ...) -> QuerySet: ...
def intersection(self, *other_qs: Any) -> QuerySet: ...
def difference(self, *other_qs: Any) -> QuerySet: ...
def select_for_update(
self, nowait: bool = ..., skip_locked: bool = ..., of: Tuple = ...
) -> QuerySet: ...
def select_related(self, *fields: Any) -> QuerySet: ...
def prefetch_related(self, *lookups: Any) -> QuerySet: ...
def annotate(self, *args: Any, **kwargs: Any) -> QuerySet: ...
def order_by(self, *field_names: Any) -> QuerySet: ...
def distinct(self, *field_names: Any) -> QuerySet: ...
def extra(
self,
select: Optional[
@@ -205,22 +266,32 @@ class QuerySet:
order_by: Optional[Union[List[str], Tuple[str]]] = ...,
select_params: Optional[Union[List[int], List[str], Tuple[int]]] = ...,
) -> QuerySet: ...
def reverse(self) -> QuerySet: ...
def defer(self, *fields: Any) -> QuerySet: ...
def only(self, *fields: Any) -> QuerySet: ...
def using(self, alias: Optional[str]) -> QuerySet: ...
@property
def ordered(self) -> bool: ...
@property
def db(self) -> str: ...
def resolve_expression(self, *args: Any, **kwargs: Any) -> Query: ...
class InstanceCheckMeta(type):
def __instancecheck__(self, instance: Union[QuerySet, str]) -> bool: ...
class EmptyQuerySet:
def __init__(self, *args: Any, **kwargs: Any) -> Any: ...
class RawQuerySet:
columns: List[str]
model_fields: Dict[str, django.db.models.fields.Field]
@@ -236,6 +307,7 @@ class RawQuerySet:
Tuple,
] = ...
translations: Dict[str, str] = ...
def __init__(
self,
raw_query: str,
@@ -255,52 +327,78 @@ class RawQuerySet:
using: Optional[str] = ...,
hints: Optional[Dict[Any, Any]] = ...,
) -> None: ...
def resolve_model_init_order(
self
) -> Tuple[List[str], List[int], List[Tuple[str, int]]]: ...
def prefetch_related(self, *lookups: Any) -> RawQuerySet: ...
def __len__(self) -> int: ...
def __bool__(self) -> bool: ...
def __iter__(self) -> Any: ...
def iterator(self) -> Iterator[Model]: ...
def __getitem__(
self, k: Union[int, slice, str]
) -> Union[List[Model], Model]: ...
@property
def db(self) -> str: ...
def using(self, alias: Any): ...
def columns(self) -> List[str]: ...
def model_fields(self) -> Dict[str, Field]: ...
class Prefetch:
prefetch_through: str = ...
prefetch_to: str = ...
queryset: Optional[django.db.models.query.QuerySet] = ...
to_attr: Optional[str] = ...
def __init__(
self,
lookup: str,
queryset: Optional[QuerySet] = ...,
to_attr: Optional[str] = ...,
) -> None: ...
def add_prefix(self, prefix: str) -> None: ...
def get_current_prefetch_to(self, level: int) -> str: ...
def get_current_to_attr(self, level: int) -> Tuple[str, Optional[bool]]: ...
def get_current_queryset(self, level: int) -> Optional[QuerySet]: ...
def __eq__(self, other: None) -> bool: ...
def __hash__(self) -> int: ...
def normalize_prefetch_lookups(
lookups: reversed, prefix: None = ...
) -> List[Prefetch]: ...
def prefetch_related_objects(
model_instances: Union[List[Model], List[UUID]], *related_lookups: Any
) -> None: ...
def get_prefetcher(
instance: Model, through_attr: str, to_attr: str
) -> Tuple[
GenericForeignKey, Union[GenericForeignKey, property], bool, bool
]: ...
def prefetch_one_level(
instances: List[Model],
prefetcher: Union[
@@ -310,6 +408,7 @@ def prefetch_one_level(
level: int,
) -> Tuple[List[Model], List[Prefetch]]: ...
class RelatedPopulator:
db: str = ...
cols_start: int = ...
@@ -321,69 +420,14 @@ class RelatedPopulator:
related_populators: List[django.db.models.query.RelatedPopulator] = ...
local_setter: Callable = ...
remote_setter: Callable = ...
def __init__(
self,
klass_info: Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
FieldCacheMixin,
],
],
klass_info: Dict[str, Any],
select: List[Tuple[Expression, Tuple[str, List[int]], Optional[str]]],
db: str,
) -> None: ...
def populate(
self,
row: Union[
@@ -394,113 +438,9 @@ class RelatedPopulator:
from_obj: Model,
) -> None: ...
def get_related_populators(
klass_info: Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
int
],
Type[
Model
],
bool,
ForeignKey,
],
]
],
List[
int
],
Type[
Model
],
bool,
ForeignKey,
],
]
],
List[
int
],
Type[
Model
],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
FieldCacheMixin,
],
]
],
List[int],
Type[Model],
bool,
FieldCacheMixin,
],
],
klass_info: Dict[str, Any],
select: List[Tuple[Expression, Tuple[str, List[bool]], Optional[str]]],
db: str,
) -> List[RelatedPopulator]: ...

View File

@@ -5,15 +5,12 @@ from typing import (Any, Callable, Dict, Iterator, List, Optional, Set, Tuple,
Type, Union)
from uuid import UUID
from django.contrib.contenttypes.models import ContentType
from django.db.backends.sqlite3.base import DatabaseWrapper
from django.db.backends.utils import CursorWrapper
from django.db.models.base import Model
from django.db.models.expressions import (BaseExpression, Col, Expression,
OrderBy, RawSQL, SQLiteNumericMixin)
from django.db.models.fields import DateTimeCheckMixin, Field
from django.db.models.fields.mixins import FieldCacheMixin
from django.db.models.fields.related import ForeignKey
from django.db.models.functions.text import Lower
from django.db.models.options import Options
from django.db.models.sql.query import Query, RawQuery
@@ -21,6 +18,7 @@ from django.utils.datastructures import ImmutableList
FORCE: Any
class SQLCompiler:
query: Any = ...
connection: Any = ...
@@ -30,15 +28,20 @@ class SQLCompiler:
annotation_col_map: Any = ...
klass_info: Any = ...
ordering_parts: Any = ...
def __init__(
self,
query: Union[Query, RawQuery],
connection: DatabaseWrapper,
using: Optional[str],
) -> None: ...
col_count: Any = ...
def setup_query(self) -> None: ...
has_extra_select: Any = ...
def pre_sql_setup(
self
) -> Tuple[
@@ -48,6 +51,7 @@ class SQLCompiler:
List[Tuple[OrderBy, Tuple[str, List[Union[int, str]], bool]]],
List[Tuple[str, List[float]]],
]: ...
def get_group_by(
self,
select: List[
@@ -59,11 +63,13 @@ class SQLCompiler:
],
order_by: List[Tuple[OrderBy, Tuple[str, List[Union[int, str]], bool]]],
) -> List[Tuple[str, List[float]]]: ...
def collapse_group_by(
self,
expressions: List[Expression],
having: Union[List[Expression], Tuple],
) -> List[Expression]: ...
def get_select(
self
) -> Tuple[
@@ -75,31 +81,15 @@ class SQLCompiler:
]
],
Optional[
Dict[
str,
Union[
List[
Dict[
str,
Union[
Callable,
List[int],
Type[ContentType],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
],
]
Dict[str, Any]
],
Dict[str, int],
]: ...
def get_order_by(
self
) -> List[Tuple[OrderBy, Tuple[str, List[Any], bool]]]: ...
def get_extra_select(
self,
order_by: List[Tuple[OrderBy, Tuple[str, List[Any], bool]]],
@@ -111,23 +101,30 @@ class SQLCompiler:
]
],
) -> List[Tuple[OrderBy, Tuple[str, List[Any]], None]]: ...
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 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 get_default_columns(
self,
start_alias: Optional[str] = ...,
opts: Optional[Options] = ...,
from_parent: Optional[Type[Model]] = ...,
) -> List[Col]: ...
def get_distinct(self) -> Tuple[List[Any], List[Any]]: ...
def find_ordering_name(
self,
name: str,
@@ -138,7 +135,9 @@ class SQLCompiler:
Set[Tuple[Optional[Tuple[Tuple[str, str]]], Tuple[Tuple[str, str]]]]
] = ...,
) -> List[Tuple[OrderBy, bool]]: ...
def get_from_clause(self) -> Tuple[List[str], List[Union[int, str]]]: ...
def get_related_selections(
self,
select: List[Tuple[Expression, Optional[str]]],
@@ -149,73 +148,18 @@ class SQLCompiler:
Union[Dict[str, Dict[str, Dict[str, Dict[Any, Any]]]], bool]
] = ...,
restricted: Optional[bool] = ...,
) -> List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[
Dict[
str,
Union[
Callable,
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
ForeignKey,
],
]
],
List[int],
Type[Model],
bool,
FieldCacheMixin,
],
]
]: ...
) -> List[Dict[str, Any]]: ...
def get_select_for_update_of_arguments(self): ...
def deferred_to_columns(self) -> Dict[Type[Model], Set[str]]: ...
def get_converters(
self, expressions: Union[List[RawSQL], List[SQLiteNumericMixin]]
) -> Dict[
int, Tuple[List[Callable], Union[Expression, SQLiteNumericMixin]]
]: ...
def apply_converters(
self,
rows: chain,
@@ -229,6 +173,7 @@ class SQLCompiler:
List[Optional[Union[datetime, float, str, UUID]]],
]
]: ...
def results_iter(
self,
results: Optional[
@@ -238,27 +183,36 @@ class SQLCompiler:
chunked_fetch: bool = ...,
chunk_size: int = ...,
) -> Union[Iterator[Any], chain, map]: ...
def has_results(self) -> bool: ...
def execute_sql(
self,
result_type: str = ...,
chunked_fetch: bool = ...,
chunk_size: int = ...,
) -> Optional[Union[Iterator[Any], CursorWrapper]]: ...
def as_subquery_condition(
self, alias: str, columns: List[str], compiler: SQLCompiler
) -> Tuple[str, Tuple]: ...
def explain_query(self) -> Iterator[str]: ...
class SQLInsertCompiler(SQLCompiler):
return_id: bool = ...
def field_as_sql(
self, field: Optional[Field], val: Optional[Union[Lower, float, str]]
) -> Tuple[str, Union[List[int], List[str]]]: ...
def prepare_value(
self, field: Field, value: Any
) -> Optional[Union[Lower, float, str]]: ...
def pre_save_val(self, field: Field, obj: Model) -> Any: ...
def assemble_as_sql(
self,
fields: Union[
@@ -268,21 +222,30 @@ class SQLInsertCompiler(SQLCompiler):
List[List[Optional[Union[Lower, int]]]], List[List[Union[int, str]]]
],
) -> Tuple[Tuple[Tuple[str]], List[List[Optional[Union[int, str]]]]]: ...
def as_sql(self) -> List[Tuple[str, Tuple[Union[float, str]]]]: ...
def execute_sql(self, return_id: Optional[bool] = ...) -> Any: ...
class SQLDeleteCompiler(SQLCompiler):
def as_sql(self) -> Tuple[str, Tuple]: ...
class SQLUpdateCompiler(SQLCompiler):
def as_sql(self) -> Tuple[str, Tuple]: ...
def execute_sql(self, result_type: str) -> int: ...
def pre_sql_setup(self) -> None: ...
class SQLAggregateCompiler(SQLCompiler):
col_count: Any = ...
def as_sql(self) -> Tuple[str, Tuple]: ...
def cursor_iter(
cursor: CursorWrapper,
sentinel: List[Any],