This commit is contained in:
Maxim Kurnikov
2019-07-21 03:31:30 +03:00
parent a0db24c764
commit 2c001fd8a7
6 changed files with 36 additions and 186 deletions

View File

@@ -30,7 +30,7 @@ class Group(models.Model):
class UserManager(BaseUserManager):
def create_user(
self, username: str, email: Optional[str] = ..., password: Optional[str] = ..., **extra_fields: Any
) -> AbstractUser: ...
) -> AbstractBaseUser: ...
def create_superuser(
self, username: str, email: Optional[str], password: Optional[str], **extra_fields: Any
) -> AbstractBaseUser: ...

View File

@@ -1,25 +1,23 @@
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, Union, Iterable
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Type, Union
from django.apps.config import AppConfig
from django.db.models.base import Model
from django.db.models.query import QuerySet
from .base import (
Serializer as Serializer,
Deserializer as Deserializer,
SerializerDoesNotExist as SerializerDoesNotExist,
SerializationError as SerializationError,
DeserializationError as DeserializationError,
M2MDeserializationError as M2MDeserializationError,
DeserializedObject,
Deserializer as Deserializer,
M2MDeserializationError as M2MDeserializationError,
SerializationError as SerializationError,
Serializer as Serializer,
SerializerDoesNotExist as SerializerDoesNotExist,
)
BUILTIN_SERIALIZERS: Any
class BadSerializer:
internal_use_only: bool = ...
exception: ModuleNotFoundError = ...
def __init__(self, exception: ImportError) -> None: ...
exception: BaseException = ...
def __init__(self, exception: BaseException) -> None: ...
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
def register_serializer(format: str, serializer_module: str, serializers: Optional[Dict[str, Any]] = ...) -> None: ...
@@ -28,8 +26,6 @@ def get_serializer(format: str) -> Union[Type[Serializer], BadSerializer]: ...
def get_serializer_formats() -> List[str]: ...
def get_public_serializer_formats() -> List[str]: ...
def get_deserializer(format: str) -> Union[Callable, Type[Deserializer]]: ...
def serialize(format: str, queryset: Iterable[Model], **options: Any) -> Optional[Union[bytes, str]]: ...
def serialize(format: str, queryset: Iterable[Model], **options: Any) -> Any: ...
def deserialize(format: str, stream_or_string: Any, **options: Any) -> Iterator[DeserializedObject]: ...
def sort_dependencies(
app_list: Union[Iterable[Tuple[AppConfig, None]], Iterable[Tuple[str, Iterable[Type[Model]]]]]
) -> List[Type[Model]]: ...
def sort_dependencies(app_list: Iterable[Any]) -> List[Type[Model]]: ...

View File

@@ -1,5 +1,5 @@
import collections
from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union, TypeVar, Generic
from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union, TypeVar, Generic, Sequence
from django.apps.config import AppConfig
from django.apps.registry import Apps
@@ -45,22 +45,22 @@ class Options(Generic[_M]):
local_many_to_many: List[ManyToManyField] = ...
private_fields: List[Any] = ...
local_managers: List[Manager] = ...
base_manager_name: None = ...
default_manager_name: None = ...
base_manager_name: Optional[str] = ...
default_manager_name: Optional[str] = ...
model_name: Optional[str] = ...
verbose_name: Optional[str] = ...
verbose_name_plural: Optional[str] = ...
db_table: str = ...
ordering: List[str] = ...
ordering: Optional[List[str]] = ...
indexes: List[Any] = ...
unique_together: Union[List[Any], Tuple] = ...
index_together: Union[List[Any], Tuple] = ...
select_on_save: bool = ...
default_permissions: Tuple[str, str, str, str] = ...
default_permissions: Sequence[str] = ...
permissions: List[Any] = ...
object_name: Optional[str] = ...
app_label: str = ...
get_latest_by: None = ...
get_latest_by: Optional[Sequence[str]] = ...
order_with_respect_to: None = ...
db_tablespace: str = ...
required_db_features: List[Any] = ...
@@ -78,7 +78,7 @@ class Options(Generic[_M]):
auto_created: bool = ...
related_fkey_lookups: List[Any] = ...
apps: Apps = ...
default_related_name: None = ...
default_related_name: Optional[str] = ...
model: Type[Model] = ...
original_attrs: Dict[str, Any] = ...
def __init__(self, meta: Optional[type], app_label: Optional[str] = ...) -> None: ...

View File

@@ -2,8 +2,8 @@ import collections
from collections import OrderedDict, namedtuple
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Type, Union
from django.db.models.lookups import Lookup
from django.db.models.query_utils import PathInfo
from django.db.models.lookups import Lookup, Transform
from django.db.models.query_utils import PathInfo, RegisterLookupMixin
from django.db.models.sql.compiler import SQLCompiler
from django.db.models.sql.datastructures import BaseTable
from django.db.models.sql.where import WhereNode
@@ -69,6 +69,8 @@ class Query:
explain_query: bool = ...
explain_format: Optional[str] = ...
explain_options: Dict[str, int] = ...
high_mark: Optional[int] = ...
low_mark: int = ...
def __init__(self, model: Optional[Type[Model]], where: Type[WhereNode] = ...) -> None: ...
@property
def extra(self) -> OrderedDict: ...
@@ -141,8 +143,6 @@ class Query:
) -> 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: ...
@@ -178,7 +178,10 @@ class Query:
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: ...
def build_lookup(self, lookups: Sequence[str], lhs: Query, rhs: Optional[Query]) -> Lookup: ...
def build_lookup(
self, lookups: Sequence[str], lhs: Union[RegisterLookupMixin, Query], rhs: Optional[Query]
) -> Lookup: ...
def try_transform(self, lhs: Union[RegisterLookupMixin, Query], name: str) -> Transform: ...
class JoinPromoter:
connector: str = ...

View File

@@ -1,104 +1,25 @@
import collections
import uuid
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple, Type, Union
from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union
from django.db.models.base import Model
from django.db.models.expressions import Case
from django.db.models.query import QuerySet
from django.db.models.sql.datastructures import BaseTable
from django.db.models.sql.query import Query
from django.db.models.sql.where import WhereNode
from django.db.models.fields import Field
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[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[WhereNode]
compiler: str = ...
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_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[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: List[Tuple[Field, Optional[Type[Model]], Union[Case, uuid.UUID]]]
values_select: Tuple
where_class: Type[WhereNode]
compiler: str = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def clone(self) -> UpdateQuery: ...
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: ...
@@ -107,87 +28,18 @@ class UpdateQuery(Query):
def get_related_updates(self) -> List[UpdateQuery]: ...
class InsertQuery(Query):
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[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: WhereNode
where_class: Type[WhereNode]
compiler: str = ...
fields: Iterable[Field] = ...
objs: List[Model] = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
raw: bool = ...
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def insert_values(self, fields: Iterable[Field], objs: List[Model], raw: bool = ...) -> None: ...
class AggregateQuery(Query):
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[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
table_map: Dict[Any, Any]
used_aliases: Set[Any]
values_select: Tuple
where: WhereNode
where_class: Type[WhereNode]
compiler: str = ...
def add_subquery(self, query: Query, using: str) -> None: ...

View File

@@ -1,5 +1,5 @@
from abc import ABCMeta, abstractmethod
from typing import Type, cast, OrderedDict
from collections import OrderedDict
from typing import Type, cast
from django.db.models.base import Model
from django.db.models.fields.related import ForeignKey
@@ -35,7 +35,7 @@ class ModelClassInitializer:
field_info = self.lookup_typeinfo_or_incomplete_defn_error(fullname)
return field_info
def create_new_var(self, name: str, typ: Instance, is_classvar=False) -> Var:
def create_new_var(self, name: str, typ: Instance) -> Var:
# type=: type of the variable itself
var = Var(name=name, type=typ)
# var.info: type of the object variable is bound to
@@ -43,11 +43,10 @@ class ModelClassInitializer:
var._fullname = self.model_classdef.info.fullname() + '.' + name
var.is_initialized_in_class = True
var.is_inferred = True
var.is_classvar = is_classvar
return var
def add_new_node_to_model_class(self, name: str, typ: Instance, is_classvar=False) -> None:
var = self.create_new_var(name, typ, is_classvar=is_classvar)
def add_new_node_to_model_class(self, name: str, typ: Instance) -> None:
var = self.create_new_var(name, typ)
self.model_classdef.info.names[name] = SymbolTableNode(MDEF, var, plugin_generated=True)
def run(self) -> None:
@@ -116,7 +115,7 @@ class AddManagers(ModelClassInitializer):
if manager_name not in self.model_classdef.info.names:
manager = Instance(manager_info, [Instance(self.model_classdef.info, [])])
self.add_new_node_to_model_class(manager_name, manager, is_classvar=True)
self.add_new_node_to_model_class(manager_name, manager)
else:
# create new MODELNAME_MANAGERCLASSNAME class that represents manager parametrized with current model
has_manager_any_base = any(self._is_manager_any(base) for base in manager_info.bases)
@@ -137,14 +136,14 @@ class AddManagers(ModelClassInitializer):
bases=bases,
fields=OrderedDict())
custom_manager_type = Instance(custom_manager_info, [Instance(self.model_classdef.info, [])])
self.add_new_node_to_model_class(manager_name, custom_manager_type, is_classvar=True)
self.add_new_node_to_model_class(manager_name, custom_manager_type)
# add _default_manager
if '_default_manager' not in self.model_classdef.info.names:
default_manager_fullname = helpers.get_class_fullname(model_cls._meta.default_manager.__class__)
default_manager_info = self.lookup_typeinfo_or_incomplete_defn_error(default_manager_fullname)
default_manager = Instance(default_manager_info, [Instance(self.model_classdef.info, [])])
self.add_new_node_to_model_class('_default_manager', default_manager, is_classvar=True)
self.add_new_node_to_model_class('_default_manager', default_manager)
# add related managers
for relation in self.django_context.get_model_relations(model_cls):