mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 14:01:56 +08:00
latest changes
This commit is contained in:
7
django-stubs/apps/__init__.pyi
Normal file
7
django-stubs/apps/__init__.pyi
Normal file
@@ -0,0 +1,7 @@
|
||||
from .config import (
|
||||
AppConfig as AppConfig
|
||||
)
|
||||
|
||||
from .registry import (
|
||||
apps as apps
|
||||
)
|
||||
26
django-stubs/apps/config.pyi
Normal file
26
django-stubs/apps/config.pyi
Normal file
@@ -0,0 +1,26 @@
|
||||
from typing import Any, Iterator, Type
|
||||
|
||||
from django.db.models.base import Model
|
||||
|
||||
MODELS_MODULE_NAME: str
|
||||
|
||||
class AppConfig:
|
||||
name: str = ...
|
||||
module: Any = ...
|
||||
apps: None = ...
|
||||
label: str = ...
|
||||
verbose_name: str = ...
|
||||
path: str = ...
|
||||
models_module: None = ...
|
||||
models: None = ...
|
||||
def __init__(self, app_name: str, app_module: None) -> None: ...
|
||||
@classmethod
|
||||
def create(cls, entry: str) -> AppConfig: ...
|
||||
def get_model(
|
||||
self, model_name: str, require_ready: bool = ...
|
||||
) -> Type[Model]: ...
|
||||
def get_models(
|
||||
self, include_auto_created: bool = ..., include_swapped: bool = ...
|
||||
) -> Iterator[Type[Model]]: ...
|
||||
def import_models(self) -> None: ...
|
||||
def ready(self) -> None: ...
|
||||
62
django-stubs/apps/registry.pyi
Normal file
62
django-stubs/apps/registry.pyi
Normal file
@@ -0,0 +1,62 @@
|
||||
import collections
|
||||
from typing import Any, Callable, List, Optional, Tuple, Type, Union, Iterable
|
||||
|
||||
from django.apps.config import AppConfig
|
||||
from django.db.migrations.state import AppConfigStub
|
||||
from django.db.models.base import Model
|
||||
|
||||
from .config import AppConfig
|
||||
|
||||
|
||||
class Apps:
|
||||
all_models: collections.defaultdict = ...
|
||||
app_configs: collections.OrderedDict = ...
|
||||
stored_app_configs: List[Any] = ...
|
||||
apps_ready: bool = ...
|
||||
loading: bool = ...
|
||||
def __init__(
|
||||
self,
|
||||
installed_apps: Optional[
|
||||
Union[List[AppConfigStub], List[str], Tuple]
|
||||
] = ...,
|
||||
) -> None: ...
|
||||
models_ready: bool = ...
|
||||
ready: bool = ...
|
||||
def populate(
|
||||
self, installed_apps: Union[List[AppConfigStub], List[str], Tuple] = ...
|
||||
) -> None: ...
|
||||
def check_apps_ready(self) -> None: ...
|
||||
def check_models_ready(self) -> None: ...
|
||||
def get_app_configs(self) -> Iterable[AppConfig]: ...
|
||||
def get_app_config(self, app_label: str) -> AppConfig: ...
|
||||
def get_models(
|
||||
self, include_auto_created: bool = ..., include_swapped: bool = ...
|
||||
) -> List[Type[Model]]: ...
|
||||
def get_model(
|
||||
self,
|
||||
app_label: str,
|
||||
model_name: Optional[str] = ...,
|
||||
require_ready: bool = ...,
|
||||
) -> Type[Model]: ...
|
||||
def register_model(self, app_label: str, model: Type[Model]) -> None: ...
|
||||
def is_installed(self, app_name: str) -> bool: ...
|
||||
def get_containing_app_config(
|
||||
self, object_name: str
|
||||
) -> Optional[AppConfig]: ...
|
||||
def get_registered_model(
|
||||
self, app_label: str, model_name: str
|
||||
) -> Type[Model]: ...
|
||||
def get_swappable_settings_name(self, to_string: str) -> Optional[str]: ...
|
||||
def set_available_apps(self, available: List[str]) -> None: ...
|
||||
def unset_available_apps(self) -> None: ...
|
||||
def set_installed_apps(
|
||||
self, installed: Union[List[str], Tuple[str]]
|
||||
) -> None: ...
|
||||
def unset_installed_apps(self) -> None: ...
|
||||
def clear_cache(self) -> None: ...
|
||||
def lazy_model_operation(
|
||||
self, function: Callable, *model_keys: Any
|
||||
) -> None: ...
|
||||
def do_pending_operations(self, model: Type[Model]) -> None: ...
|
||||
|
||||
apps: Apps
|
||||
@@ -1,2 +1,18 @@
|
||||
from typing import Any
|
||||
|
||||
from .utils import (ProgrammingError as ProgrammingError,
|
||||
IntegrityError as IntegrityError)
|
||||
IntegrityError as IntegrityError,
|
||||
OperationalError as OperationalError,
|
||||
DatabaseError as DatabaseError,
|
||||
DataError as DataError,
|
||||
NotSupportedError as NotSupportedError)
|
||||
|
||||
connections: Any
|
||||
router: Any
|
||||
|
||||
class DefaultConnectionProxy:
|
||||
def __getattr__(self, item: str) -> Any: ...
|
||||
def __setattr__(self, name: str, value: Any) -> None: ...
|
||||
def __delattr__(self, name: str) -> None: ...
|
||||
|
||||
connection: Any
|
||||
|
||||
@@ -3,14 +3,21 @@ from .base import Model as Model
|
||||
from .fields import (AutoField as AutoField,
|
||||
IntegerField as IntegerField,
|
||||
SmallIntegerField as SmallIntegerField,
|
||||
BigIntegerField as BigIntegerField,
|
||||
CharField as CharField,
|
||||
Field as Field,
|
||||
SlugField as SlugField,
|
||||
TextField as TextField,
|
||||
BooleanField as BooleanField)
|
||||
BooleanField as BooleanField,
|
||||
FileField as FileField,
|
||||
DateField as DateField,
|
||||
DateTimeField as DateTimeField,
|
||||
IPAddressField as IPAddressField,
|
||||
GenericIPAddressField as GenericIPAddressField)
|
||||
|
||||
from .fields.related import (ForeignKey as ForeignKey,
|
||||
OneToOneField as OneToOneField)
|
||||
OneToOneField as OneToOneField,
|
||||
ManyToManyField as ManyToManyField)
|
||||
|
||||
from .deletion import (CASCADE as CASCADE,
|
||||
SET_DEFAULT as SET_DEFAULT,
|
||||
@@ -24,4 +31,11 @@ from .query_utils import Q as Q
|
||||
|
||||
from .lookups import Lookup as Lookup
|
||||
|
||||
from .expressions import F as F
|
||||
from .expressions import (F as F,
|
||||
Subquery as Subquery,
|
||||
Exists as Exists,
|
||||
OrderBy as OrderBy,
|
||||
OuterRef as OuterRef)
|
||||
|
||||
from .manager import (BaseManager as BaseManager,
|
||||
Manager as Manager)
|
||||
|
||||
@@ -3,6 +3,7 @@ from datetime import datetime, timedelta
|
||||
from typing import (Any, Callable, Dict, Iterator, List, Optional, Set, Tuple,
|
||||
Type, Union)
|
||||
|
||||
from django.db.models import QuerySet
|
||||
from django.db.models.fields import Field
|
||||
from django.db.models.lookups import Lookup
|
||||
from django.db.models.sql.compiler import SQLCompiler
|
||||
@@ -180,4 +181,50 @@ class CombinedExpression(SQLiteNumericMixin, Expression):
|
||||
|
||||
|
||||
class F(Combinable):
|
||||
def __init__(self, name: str): ...
|
||||
name: str
|
||||
def __init__(self, name: str): ...
|
||||
def resolve_expression(
|
||||
self,
|
||||
query: Any = ...,
|
||||
allow_joins: bool = ...,
|
||||
reuse: Optional[Set[str]] = ...,
|
||||
summarize: bool = ...,
|
||||
for_save: bool = ...,
|
||||
) -> Expression: ...
|
||||
|
||||
|
||||
class OuterRef(F): ...
|
||||
|
||||
class Subquery(Expression):
|
||||
template: str = ...
|
||||
queryset: QuerySet = ...
|
||||
extra: Dict[Any, Any] = ...
|
||||
def __init__(
|
||||
self,
|
||||
queryset: QuerySet,
|
||||
output_field: Optional[Field] = ...,
|
||||
**extra: Any
|
||||
) -> None: ...
|
||||
|
||||
class Exists(Subquery):
|
||||
extra: Dict[Any, Any]
|
||||
template: str = ...
|
||||
negated: bool = ...
|
||||
def __init__(
|
||||
self, *args: Any, negated: bool = ..., **kwargs: Any
|
||||
) -> None: ...
|
||||
def __invert__(self) -> Exists: ...
|
||||
|
||||
class OrderBy(BaseExpression):
|
||||
template: str = ...
|
||||
nulls_first: bool = ...
|
||||
nulls_last: bool = ...
|
||||
descending: bool = ...
|
||||
expression: Expression = ...
|
||||
def __init__(
|
||||
self,
|
||||
expression: Combinable,
|
||||
descending: bool = ...,
|
||||
nulls_first: bool = ...,
|
||||
nulls_last: bool = ...,
|
||||
) -> None: ...
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any
|
||||
from typing import Any, Optional
|
||||
|
||||
from django.db.models.query_utils import RegisterLookupMixin
|
||||
|
||||
@@ -7,6 +7,7 @@ class Field(RegisterLookupMixin):
|
||||
def __init__(self,
|
||||
primary_key: bool = False,
|
||||
**kwargs): ...
|
||||
|
||||
def __get__(self, instance, owner) -> Any: ...
|
||||
|
||||
|
||||
@@ -14,8 +15,10 @@ class IntegerField(Field):
|
||||
def __get__(self, instance, owner) -> int: ...
|
||||
|
||||
|
||||
class SmallIntegerField(IntegerField):
|
||||
pass
|
||||
class SmallIntegerField(IntegerField): ...
|
||||
|
||||
|
||||
class BigIntegerField(IntegerField): ...
|
||||
|
||||
|
||||
class AutoField(Field):
|
||||
@@ -26,11 +29,11 @@ class CharField(Field):
|
||||
def __init__(self,
|
||||
max_length: int,
|
||||
**kwargs): ...
|
||||
|
||||
def __get__(self, instance, owner) -> str: ...
|
||||
|
||||
|
||||
class SlugField(CharField):
|
||||
pass
|
||||
class SlugField(CharField): ...
|
||||
|
||||
|
||||
class TextField(Field):
|
||||
@@ -39,3 +42,29 @@ class TextField(Field):
|
||||
|
||||
class BooleanField(Field):
|
||||
def __get__(self, instance, owner) -> bool: ...
|
||||
|
||||
|
||||
class FileField(Field): ...
|
||||
|
||||
|
||||
class IPAddressField(Field): ...
|
||||
|
||||
|
||||
class GenericIPAddressField(Field):
|
||||
default_error_messages: Any = ...
|
||||
unpack_ipv4: Any = ...
|
||||
protocol: Any = ...
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
verbose_name: Optional[Any] = ...,
|
||||
name: Optional[Any] = ...,
|
||||
protocol: str = ...,
|
||||
unpack_ipv4: bool = ...,
|
||||
*args: Any,
|
||||
**kwargs: Any
|
||||
) -> None: ...
|
||||
|
||||
class DateField(Field): ...
|
||||
|
||||
class DateTimeField(DateField): ...
|
||||
@@ -22,3 +22,12 @@ class OneToOneField(Field, Generic[_T]):
|
||||
related_name: str = ...,
|
||||
**kwargs): ...
|
||||
def __get__(self, instance, owner) -> _T: ...
|
||||
|
||||
|
||||
class ManyToManyField(Field, Generic[_T]):
|
||||
def __init__(self,
|
||||
to: Union[Type[_T], str],
|
||||
on_delete: Any,
|
||||
related_name: str = ...,
|
||||
**kwargs): ...
|
||||
def __get__(self, instance, owner) -> _T: ...
|
||||
|
||||
140
django-stubs/db/models/manager.pyi
Normal file
140
django-stubs/db/models/manager.pyi
Normal file
@@ -0,0 +1,140 @@
|
||||
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 django.db.models import Q
|
||||
from django.db.models.base import Model
|
||||
from django.db.models.query import QuerySet, RawQuerySet
|
||||
|
||||
_T = TypeVar('_T', bound=Model)
|
||||
|
||||
|
||||
class BaseManager:
|
||||
creation_counter: int = ...
|
||||
auto_created: bool = ...
|
||||
use_in_migrations: bool = ...
|
||||
def __new__(cls: Type[BaseManager], *args: Any, **kwargs: Any) -> BaseManager: ...
|
||||
model: Any = ...
|
||||
name: Any = ...
|
||||
def __init__(self) -> None: ...
|
||||
def deconstruct(self) -> Tuple[bool, str, None, Tuple, Dict[str, int]]: ...
|
||||
def check(self, **kwargs: Any) -> List[Any]: ...
|
||||
@classmethod
|
||||
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): ...
|
||||
|
||||
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 ManagerDescriptor:
|
||||
manager: Manager = ...
|
||||
def __init__(self, manager: Manager) -> None: ...
|
||||
def __get__(
|
||||
self, instance: Optional[Model], cls: Type[Model] = ...
|
||||
) -> Manager: ...
|
||||
|
||||
class EmptyManager(Manager):
|
||||
creation_counter: int
|
||||
name: None
|
||||
model: Optional[Type[Model]] = ...
|
||||
def __init__(self, model: Type[Model]) -> None: ...
|
||||
def get_queryset(self) -> QuerySet: ...
|
||||
@@ -6,4 +6,9 @@ from .conf import (include as include,
|
||||
|
||||
from .resolvers import (ResolverMatch as ResolverMatch,
|
||||
get_ns_resolver as get_ns_resolver,
|
||||
get_resolver as get_resolver)
|
||||
get_resolver as get_resolver)
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
from .converters import (
|
||||
register_converter as register_converter
|
||||
)
|
||||
30
django-stubs/utils/baseconv.pyi
Normal file
30
django-stubs/utils/baseconv.pyi
Normal file
@@ -0,0 +1,30 @@
|
||||
from typing import Any, Tuple, Union
|
||||
|
||||
BASE2_ALPHABET: str
|
||||
BASE16_ALPHABET: str
|
||||
BASE56_ALPHABET: str
|
||||
BASE36_ALPHABET: str
|
||||
BASE62_ALPHABET: str
|
||||
BASE64_ALPHABET: Any
|
||||
|
||||
class BaseConverter:
|
||||
decimal_digits: str = ...
|
||||
sign: str = ...
|
||||
digits: str = ...
|
||||
def __init__(self, digits: str, sign: str = ...) -> None: ...
|
||||
def encode(self, i: int) -> str: ...
|
||||
def decode(self, s: str) -> int: ...
|
||||
def convert(
|
||||
self,
|
||||
number: Union[int, str],
|
||||
from_digits: str,
|
||||
to_digits: str,
|
||||
sign: str,
|
||||
) -> Tuple[int, str]: ...
|
||||
|
||||
base2: Any
|
||||
base16: Any
|
||||
base36: Any
|
||||
base56: Any
|
||||
base62: Any
|
||||
base64: Any
|
||||
Reference in New Issue
Block a user