Add lots of missing argument & return type hints (#1204)

* Add lots of missing argument & return type hints

Discovered by setting mypy options disallow_untyped_defs, disallow_incomplete_defs.

* Sequence -> List

* Fixes from review

* Drop ordering_field

* Revert ModelBackend.with_perm

* typing_extensions.TypedDict instead

* bla

* Remove private method _get_lines_from_file

* A few additions

* Hints for BaseSpatialFeatures
This commit is contained in:
Marti Raudsepp
2022-10-28 13:08:00 +03:00
committed by GitHub
parent e20d5307d1
commit 36044c98b8
58 changed files with 218 additions and 164 deletions

View File

@@ -83,7 +83,7 @@ DATABASES: Dict[str, Dict[str, Any]] = ...
# Classes used to implement DB routing behavior.
class Router(Protocol):
def allow_migrate(self, db, app_label, **hints): ...
def allow_migrate(self, db: str, app_label: str, **hints: Any) -> Optional[bool]: ...
DATABASE_ROUTERS: List[Union[str, Router]] = ...

View File

@@ -1,21 +1,21 @@
from typing import Any, Optional, Sequence
from typing import Any, List, Optional, Sequence
from django.apps.config import AppConfig
from django.contrib.admin.options import BaseModelAdmin
from django.core.checks.messages import CheckMessage, Error
def check_admin_app(app_configs: Optional[Sequence[AppConfig]], **kwargs: Any) -> Sequence[CheckMessage]: ...
def check_dependencies(**kwargs: Any) -> Sequence[CheckMessage]: ...
def check_admin_app(app_configs: Optional[Sequence[AppConfig]], **kwargs: Any) -> List[CheckMessage]: ...
def check_dependencies(**kwargs: Any) -> List[CheckMessage]: ...
class BaseModelAdminChecks:
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> Sequence[CheckMessage]: ...
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> List[CheckMessage]: ...
class ModelAdminChecks(BaseModelAdminChecks):
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> Sequence[CheckMessage]: ...
def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> List[CheckMessage]: ...
class InlineModelAdminChecks(BaseModelAdminChecks):
def check(self, inline_obj: BaseModelAdmin, **kwargs: Any) -> Sequence[CheckMessage]: ... # type: ignore
def check(self, inline_obj: BaseModelAdmin, **kwargs: Any) -> List[CheckMessage]: ... # type: ignore
def must_be(type: Any, option: Any, obj: Any, id: Any): ...
def must_inherit_from(parent: Any, option: Any, obj: Any, id: Any): ...
def refer_to_missing_field(field: Any, option: Any, obj: Any, id: Any): ...
def must_be(type: Any, option: Any, obj: Any, id: Any) -> List[CheckMessage]: ...
def must_inherit_from(parent: Any, option: Any, obj: Any, id: Any) -> List[CheckMessage]: ...
def refer_to_missing_field(field: Any, option: Any, obj: Any, id: Any) -> List[CheckMessage]: ...

View File

@@ -4,6 +4,7 @@ from django import forms
from django.contrib.admin.options import ModelAdmin
from django.db.models import Model
from django.db.models.fields import AutoField
from django.forms import BaseForm
from django.forms.boundfield import BoundField
from django.forms.models import ModelForm
from django.forms.utils import ErrorDict, ErrorList
@@ -143,7 +144,7 @@ class InlineAdminFormSet:
def fields(self) -> Iterator[Dict[str, Union[Dict[str, bool], bool, Widget, str]]]: ...
def inline_formset_data(self) -> str: ...
@property
def forms(self): ...
def forms(self) -> List[BaseForm]: ...
@property
def non_form_errors(self) -> Callable[[], ErrorList]: ...
@property
@@ -170,7 +171,6 @@ class InlineAdminForm(AdminForm):
def pk_field(self) -> AdminField: ...
def fk_field(self) -> AdminField: ...
def deletion_field(self) -> AdminField: ...
def ordering_field(self): ...
class InlineFieldset(Fieldset):
formset: Any = ...

View File

@@ -34,7 +34,13 @@ from django.forms.fields import Field as FormField
from django.forms.fields import TypedChoiceField
from django.forms.forms import BaseForm
from django.forms.formsets import BaseFormSet
from django.forms.models import BaseInlineFormSet, ModelChoiceField, ModelMultipleChoiceField
from django.forms.models import (
BaseInlineFormSet,
BaseModelFormSet,
ModelChoiceField,
ModelForm,
ModelMultipleChoiceField,
)
from django.forms.widgets import Media
from django.http.request import HttpRequest
from django.http.response import HttpResponse, HttpResponseRedirect, JsonResponse
@@ -191,8 +197,10 @@ class ModelAdmin(BaseModelAdmin[_ModelT]):
def get_object(
self, request: HttpRequest, object_id: str, from_field: Optional[str] = ...
) -> Optional[_ModelT]: ...
def get_changelist_form(self, request: Any, **kwargs: Any): ...
def get_changelist_formset(self, request: Any, **kwargs: Any): ...
def get_changelist_form(self, request: Any, **kwargs: Any) -> Type[ModelForm[_ModelT]]: ...
def get_changelist_formset(
self, request: Any, **kwargs: Any
) -> Type[BaseModelFormSet[_ModelT, ModelForm[_ModelT]]]: ...
def get_formsets_with_inlines(self, request: HttpRequest, obj: Optional[_ModelT] = ...) -> Iterator[Any]: ...
def get_paginator(
self,

View File

@@ -14,7 +14,7 @@ from django.forms.forms import BaseForm
from django.forms.formsets import BaseFormSet
from django.http.request import HttpRequest
from django.utils.datastructures import _IndexableCollection
from typing_extensions import Literal
from typing_extensions import Literal, TypedDict
class FieldIsAForeignKeyColumnName(Exception): ...
@@ -45,7 +45,11 @@ class NestedObjects(Collector):
def nested(self, format_callback: Callable = ...) -> List[Any]: ...
def can_fast_delete(self, *args: Any, **kwargs: Any) -> bool: ...
def model_format_dict(obj: Union[Model, Type[Model], QuerySet, Options[Model]]): ...
class ModelFormatDict(TypedDict):
verbose_name: str
verbose_name_plural: str
def model_format_dict(obj: Union[Model, Type[Model], QuerySet, Options[Model]]) -> ModelFormatDict: ...
def model_ngettext(obj: Union[Options, QuerySet], n: Optional[int] = ...) -> str: ...
def lookup_field(
name: Union[Callable, str], obj: Model, model_admin: Optional[BaseModelAdmin] = ...

View File

@@ -1,10 +1,12 @@
from typing import Any, Callable, Dict, Optional, Tuple
from typing import Any, Callable, Dict, List, Optional, Tuple
from django.utils.safestring import SafeString
docutils_is_available: bool
def get_view_name(view_func: Callable) -> str: ...
def parse_docstring(docstring: str) -> Tuple[str, str, Dict[str, str]]: ...
def parse_rst(text: str, default_reference_context: Any, thing_being_parsed: Optional[Any] = ...): ...
def parse_rst(text: str, default_reference_context: Any, thing_being_parsed: Optional[Any] = ...) -> SafeString: ...
ROLES: Dict[str, str]
@@ -17,7 +19,7 @@ def default_reference_role(
inliner: Any,
options: Optional[Any] = ...,
content: Optional[Any] = ...,
): ...
) -> Tuple[List[Any], List[Any]]: ...
named_group_matcher: Any
unnamed_group_matcher: Any

View File

@@ -16,7 +16,7 @@ class ModelIndexView(BaseAdminDocsView): ...
class ModelDetailView(BaseAdminDocsView): ...
class TemplateDetailView(BaseAdminDocsView): ...
def get_return_data_type(func_name: Any): ...
def get_return_data_type(func_name: Any) -> str: ...
def get_readable_field_data_type(field: Union[Field, str]) -> str: ...
def extract_views_from_urlpatterns(
urlpatterns: Iterable[_AnyURL], base: str = ..., namespace: Optional[str] = ...

View File

@@ -2,6 +2,7 @@ from typing import Any, Optional, Set, TypeVar, Union
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import AnonymousUser, Permission
from django.db.models import QuerySet
from django.db.models.base import Model
from django.http.request import HttpRequest
@@ -33,7 +34,7 @@ class ModelBackend(BaseBackend):
is_active: bool = ...,
include_superusers: bool = ...,
obj: Optional[Model] = ...,
): ...
) -> QuerySet[AbstractBaseUser]: ...
class AllowAllUsersModelBackend(ModelBackend): ...

View File

@@ -5,6 +5,7 @@ from django.contrib.auth.base_user import BaseUserManager as BaseUserManager
from django.contrib.auth.validators import UnicodeUsernameValidator
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import QuerySet
from django.db.models.base import Model
from django.db.models.manager import EmptyManager
from typing_extensions import Literal
@@ -51,7 +52,7 @@ class UserManager(BaseUserManager[_T]):
include_superusers: bool = ...,
backend: Optional[str] = ...,
obj: Optional[Model] = ...,
): ...
) -> QuerySet[_T]: ...
class PermissionsMixin(models.Model):
is_superuser = models.BooleanField()

View File

@@ -1,4 +1,4 @@
from typing import Any, Optional, Set
from typing import Any, Dict, Optional, Set
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.forms import AuthenticationForm
@@ -35,7 +35,7 @@ def redirect_to_login(
class PasswordContextMixin:
extra_context: Any = ...
def get_context_data(self, **kwargs: Any): ...
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ...
class PasswordResetView(PasswordContextMixin, FormView):
email_template_name: str = ...

View File

@@ -90,4 +90,4 @@ class GenericRelation(ForeignObject):
class ReverseGenericManyToOneDescriptor(ReverseManyToOneDescriptor): ...
def create_generic_related_manager(superclass: Any, rel: Any): ...
def create_generic_related_manager(superclass: Any, rel: Any) -> Type[Any]: ... # GenericRelatedObjectManager

View File

@@ -1,8 +1,12 @@
from typing import Any, Optional
from typing import Any, Optional, Type, TypeVar
from django.forms.models import BaseModelFormSet
from django.db.models import Model
from django.forms.models import BaseModelFormSet, ModelForm
class BaseGenericInlineFormSet(BaseModelFormSet):
_M = TypeVar("_M", bound=Model)
_ModelFormT = TypeVar("_ModelFormT", bound=ModelForm)
class BaseGenericInlineFormSet(BaseModelFormSet[_M, _ModelFormT]):
instance: Any = ...
rel_name: Any = ...
save_as_new: Any = ...
@@ -16,14 +20,14 @@ class BaseGenericInlineFormSet(BaseModelFormSet):
queryset: Optional[Any] = ...,
**kwargs: Any
) -> None: ...
def initial_form_count(self): ...
def initial_form_count(self) -> int: ...
@classmethod
def get_default_prefix(cls): ...
def save_new(self, form: Any, commit: bool = ...): ...
def get_default_prefix(cls) -> str: ...
def save_new(self, form: Any, commit: bool = ...) -> _M: ...
def generic_inlineformset_factory(
model: Any,
form: Any = ...,
model: Type[_M],
form: Type[_ModelFormT] = ...,
formset: Any = ...,
ct_field: str = ...,
fk_field: str = ...,
@@ -40,4 +44,4 @@ def generic_inlineformset_factory(
validate_min: bool = ...,
absolute_max: Optional[int] = ...,
can_delete_extra: bool = ...,
): ...
) -> Type[BaseGenericInlineFormSet[_M, _ModelFormT]]: ...

View File

@@ -20,25 +20,25 @@ class BaseSpatialFeatures:
supports_raster: bool = ...
supports_geometry_field_unique_index: bool = ...
@property
def supports_bbcontains_lookup(self): ...
def supports_bbcontains_lookup(self) -> bool: ...
@property
def supports_contained_lookup(self): ...
def supports_contained_lookup(self) -> bool: ...
@property
def supports_crosses_lookup(self): ...
def supports_crosses_lookup(self) -> bool: ...
@property
def supports_distances_lookups(self): ...
def supports_distances_lookups(self) -> bool: ...
@property
def supports_dwithin_lookup(self): ...
def supports_dwithin_lookup(self) -> bool: ...
@property
def supports_relate_lookup(self): ...
def supports_relate_lookup(self) -> bool: ...
@property
def supports_isvalid_lookup(self): ...
def supports_isvalid_lookup(self) -> bool: ...
@property
def supports_collect_aggr(self): ...
def supports_collect_aggr(self) -> bool: ...
@property
def supports_extent_aggr(self): ...
def supports_extent_aggr(self) -> bool: ...
@property
def supports_make_line_aggr(self): ...
def supports_make_line_aggr(self) -> bool: ...
@property
def supports_union_aggr(self): ...
def __getattr__(self, name: Any): ...
def supports_union_aggr(self) -> bool: ...
def __getattr__(self, name: Any) -> bool: ...

View File

@@ -4,4 +4,4 @@ from django.db.backends.sqlite3.features import DatabaseFeatures as SQLiteDataba
class DatabaseFeatures(BaseSpatialFeatures, SQLiteDatabaseFeatures):
supports_3d_storage: bool = ...
@property
def supports_area_geodetic(self): ...
def supports_area_geodetic(self) -> bool: ... # type: ignore[override]

View File

@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Set
from django.contrib.gis.db.backends.base.operations import BaseSpatialOperations
from django.contrib.gis.db.backends.utils import SpatialOperator as SpatialOperator
@@ -19,7 +19,7 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
select: str = ...
function_names: Any = ...
@property
def unsupported_functions(self): ...
def unsupported_functions(self) -> Set[str]: ... # type: ignore[override]
@property
def spatial_version(self): ...
def geo_db_type(self, f: Any) -> None: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Optional
from typing import Any, Iterator, List, Optional
from django.http.request import HttpRequest
from django.http.response import HttpResponseBase
@@ -21,8 +21,8 @@ class BaseStorage:
added_new: bool = ...
def __init__(self, request: HttpRequest, *args: Any, **kwargs: Any) -> None: ...
def __len__(self) -> int: ...
def __iter__(self): ...
def __contains__(self, item: Any): ...
def __iter__(self) -> Iterator[Message]: ...
def __contains__(self, item: Any) -> bool: ...
def update(self, response: HttpResponseBase) -> Optional[List[Message]]: ...
def add(self, level: int, message: str, extra_tags: Optional[str] = ...) -> None: ...
level: Any = ...

View File

@@ -4,13 +4,13 @@ from django.db.models import Field, Transform
from django.db.models.fields.mixins import CheckFieldDefaultMixin
class HStoreField(CheckFieldDefaultMixin, Field):
def get_transform(self, name) -> Any: ...
def get_transform(self, name: str) -> Any: ...
class KeyTransform(Transform):
def __init__(self, key_name: str, *args: Any, **kwargs: Any): ...
def __init__(self, key_name: str, *args: Any, **kwargs: Any) -> None: ...
class KeyTransformFactory:
def __init__(self, key_name: str): ...
def __init__(self, key_name: str) -> None: ...
def __call__(self, *args, **kwargs) -> KeyTransform: ...
class KeysTransform(Transform): ...

View File

@@ -1,4 +1,6 @@
from typing import Set, Tuple
from django.db.migrations.serializer import BaseSerializer as BaseSerializer
class RangeSerializer(BaseSerializer):
def serialize(self): ...
def serialize(self) -> Tuple[str, Set[str]]: ...

View File

@@ -1,3 +1,5 @@
from typing import Any
def prefix_validation_error(error: Any, prefix: Any, code: Any, params: Any): ...
from django.core.exceptions import ValidationError
def prefix_validation_error(error: Any, prefix: Any, code: Any, params: Any) -> ValidationError: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Type
from typing import Any, List, Type
from django.utils.connection import BaseConnectionHandler, ConnectionProxy
@@ -12,7 +12,7 @@ class CacheHandler(BaseConnectionHandler):
settings_name: str = ...
exception_class: Type[Exception] = ...
def create_connection(self, alias: str) -> BaseCache: ...
def all(self, initialized_only: bool = ...): ...
def all(self, initialized_only: bool = ...) -> List[BaseCache]: ...
def close_caches(**kwargs: Any) -> None: ...

View File

@@ -1,10 +1,19 @@
from types import ModuleType
from typing import Any, Dict, Sequence, Type, Union
from django.core.cache.backends.base import BaseCache
class BaseMemcachedCache(BaseCache):
def __init__(self, server, params, library, value_not_found_exception) -> None: ...
def __init__(
self,
server: Union[str, Sequence[str]],
params: Dict[str, Any],
library: ModuleType,
value_not_found_exception: Type[BaseException],
) -> None: ...
class MemcachedCache(BaseMemcachedCache):
def __init__(self, server, params): ...
def __init__(self, server: Union[str, Sequence[str]], params: Dict[str, Any]) -> None: ...
class PyLibMCCache(BaseMemcachedCache):
def __init__(self, server, params): ...
def __init__(self, server: Union[str, Sequence[str]], params: Dict[str, Any]) -> None: ...

View File

@@ -13,7 +13,7 @@ class ManagementUtility:
prog_name: str = ...
settings_exception: Optional[Exception] = ...
def __init__(self, argv: Optional[List[str]] = ...) -> None: ...
def main_help_text(self, commands_only: bool = ...): ...
def main_help_text(self, commands_only: bool = ...) -> str: ...
def fetch_command(self, subcommand: str) -> BaseCommand: ...
def autocomplete(self) -> None: ...
def execute(self) -> None: ...

View File

@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Optional
from django.apps import apps as apps
from django.core.management.base import BaseCommand as BaseCommand
@@ -10,4 +10,4 @@ from django.db.migrations.loader import MigrationLoader as MigrationLoader
class Command(BaseCommand):
output_transaction: bool = ...
def execute(self, *args: Any, **options: Any): ...
def execute(self, *args: Any, **options: Any) -> Optional[str]: ...

View File

@@ -4,10 +4,11 @@ from django.core.serializers.base import DeserializedObject
from django.core.serializers.python import Serializer as PythonSerializer
from django.db.models.fields import Field
from yaml import CSafeDumper as SafeDumper
from yaml import MappingNode, ScalarNode
class DjangoSafeDumper(SafeDumper):
def represent_decimal(self, data: Any): ...
def represent_ordered_dict(self, data: Any): ...
def represent_decimal(self, data: Any) -> ScalarNode: ...
def represent_ordered_dict(self, data: Any) -> MappingNode: ...
class Serializer(PythonSerializer):
internal_use_only: bool = ...

View File

@@ -16,7 +16,7 @@ class BaseDatabaseCreation:
def serialize_db_to_string(self) -> str: ...
def deserialize_db_from_string(self, data: str) -> None: ...
def clone_test_db(self, suffix: Any, verbosity: int = ..., autoclobber: bool = ..., keepdb: bool = ...) -> None: ...
def get_test_db_clone_settings(self, suffix: str): ...
def get_test_db_clone_settings(self, suffix: str) -> Dict[str, Any]: ...
def destroy_test_db(
self,
old_database_name: Optional[str] = ...,
@@ -24,5 +24,5 @@ class BaseDatabaseCreation:
keepdb: bool = ...,
suffix: Optional[str] = ...,
) -> None: ...
def sql_table_creation_suffix(self): ...
def sql_table_creation_suffix(self) -> str: ...
def test_db_signature(self) -> Tuple[str, str, str, str]: ...

View File

@@ -27,7 +27,7 @@ class BaseDatabaseOperations:
connection: BaseDatabaseWrapper
def __init__(self, connection: BaseDatabaseWrapper) -> None: ...
def autoinc_sql(self, table: str, column: str) -> Optional[str]: ...
def bulk_batch_size(self, fields: Any, objs: Any): ...
def bulk_batch_size(self, fields: Any, objs: Any) -> int: ...
def cache_key_culling_sql(self) -> str: ...
def unification_cast_sql(self, output_field: Field) -> str: ...
def date_extract_sql(self, lookup_type: str, field_name: str) -> Any: ...
@@ -92,11 +92,11 @@ class BaseDatabaseOperations:
def check_expression_support(self, expression: Any) -> None: ...
def conditional_expression_supported_in_where_clause(self, expression: Any) -> bool: ...
def combine_expression(self, connector: str, sub_expressions: List[str]) -> str: ...
def combine_duration_expression(self, connector: Any, sub_expressions: Any): ...
def combine_duration_expression(self, connector: Any, sub_expressions: Any) -> str: ...
def binary_placeholder_sql(self, value: Optional[Case]) -> str: ...
def modify_insert_params(self, placeholder: str, params: Any) -> Any: ...
def integer_field_range(self, internal_type: Any) -> Tuple[int, int]: ...
def subtract_temporals(self, internal_type: Any, lhs: Any, rhs: Any): ...
def subtract_temporals(self, internal_type: Any, lhs: Any, rhs: Any) -> Tuple[str, Tuple[Any, ...]]: ...
def window_frame_start(self, start: Any) -> str: ...
def window_frame_end(self, end: Any) -> str: ...
def window_frame_rows_start_end(self, start: Optional[int] = ..., end: Optional[int] = ...) -> Tuple[str, str]: ...

View File

@@ -60,7 +60,7 @@ class BaseDatabaseSchemaEditor(ContextManager[Any]):
def column_sql(
self, model: Type[Model], field: Field, include_default: bool = ...
) -> Union[Tuple[None, None], Tuple[str, List[Any]]]: ...
def skip_default(self, field: Any): ...
def skip_default(self, field: Any) -> bool: ...
def prepare_default(self, value: Any) -> Any: ...
def effective_default(self, field: Field) -> Union[int, str]: ...
def quote_value(self, value: Any) -> str: ...
@@ -82,7 +82,7 @@ class BaseDatabaseSchemaEditor(ContextManager[Any]):
) -> None: ...
def alter_db_table(self, model: Type[Model], old_db_table: str, new_db_table: str) -> None: ...
def alter_db_tablespace(self, model: Any, old_db_tablespace: Any, new_db_tablespace: Any) -> None: ...
def add_field(self, model: Any, field: Any): ...
def remove_field(self, model: Any, field: Any): ...
def add_field(self, model: Any, field: Any) -> None: ...
def remove_field(self, model: Any, field: Any) -> None: ...
def alter_field(self, model: Type[Model], old_field: Field, new_field: Field, strict: bool = ...) -> None: ...
def remove_procedure(self, procedure_name: Any, param_types: Any = ...) -> None: ...

View File

@@ -8,8 +8,8 @@ class _QuoteCallable(Protocol):
def __call__(self, __column: str) -> str: ...
class Reference:
def references_table(self, table: Any): ...
def references_column(self, table: Any, column: Any): ...
def references_table(self, table: Any) -> bool: ...
def references_column(self, table: Any, column: Any) -> bool: ...
def rename_table_references(self, old_table: Any, new_table: Any) -> None: ...
def rename_column_references(self, table: Any, old_column: Any, new_column: Any) -> None: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Container, Dict, Optional, Tuple, Type
from typing import Any, Container, Dict, Iterator, Optional, Tuple, Type
from django.db.backends.base.base import BaseDatabaseWrapper as BaseDatabaseWrapper
from typing_extensions import Literal
@@ -18,10 +18,10 @@ class CursorWrapper:
codes_for_integrityerror: Any = ...
cursor: Any = ...
def __init__(self, cursor: Any) -> None: ...
def execute(self, query: Any, args: Optional[Any] = ...): ...
def executemany(self, query: Any, args: Any): ...
def __getattr__(self, attr: Any): ...
def __iter__(self) -> Any: ...
def execute(self, query: Any, args: Optional[Any] = ...) -> Any: ...
def executemany(self, query: Any, args: Any) -> Any: ...
def __getattr__(self, attr: Any) -> Any: ...
def __iter__(self) -> Iterator[Any]: ...
class DatabaseWrapper(BaseDatabaseWrapper):
client: DatabaseClient
@@ -48,9 +48,9 @@ class DatabaseWrapper(BaseDatabaseWrapper):
SchemaEditorClass: Any = ...
isolation_level: Any = ...
def get_connection_params(self) -> Dict[str, Any]: ...
def get_new_connection(self, conn_params: Any): ...
def get_new_connection(self, conn_params: Any) -> Any: ...
def init_connection_state(self) -> None: ...
def create_cursor(self, name: Optional[Any] = ...): ...
def create_cursor(self, name: Optional[Any] = ...) -> CursorWrapper: ...
def disable_constraint_checking(self) -> Literal[True]: ...
needs_rollback: Any = ...
def enable_constraint_checking(self) -> None: ...

View File

@@ -4,7 +4,7 @@ from django.db.models.sql import compiler as compiler
from django.db.models.sql.compiler import _AsSqlType
class SQLCompiler(compiler.SQLCompiler):
def as_subquery_condition(self, alias: Any, columns: Any, compiler: Any): ...
def as_subquery_condition(self, alias: Any, columns: Any, compiler: Any) -> _AsSqlType: ...
class SQLInsertCompiler(compiler.SQLInsertCompiler, SQLCompiler): ...

View File

@@ -18,9 +18,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
sql_delete_pk: str = ...
sql_create_index: str = ...
@property
def sql_delete_check(self): ...
def sql_delete_check(self) -> str: ... # type: ignore[override]
@property
def sql_rename_column(self): ...
def quote_value(self, value: Any): ...
def skip_default(self, field: Any): ...
def sql_rename_column(self) -> str: ... # type: ignore[override]
def quote_value(self, value: Any) -> str: ...
def skip_default(self, field: Any) -> bool: ...
def add_field(self, model: Any, field: Any) -> None: ...

View File

@@ -15,9 +15,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
sql_create_column_inline_fk: str = ...
sql_delete_table: str = ...
sql_create_index: str = ...
def quote_value(self, value: Any): ...
def quote_value(self, value: Any) -> str: ...
def remove_field(self, model: Any, field: Any) -> None: ...
def delete_model(self, model: Any) -> None: ...
def alter_field(self, model: Any, old_field: Any, new_field: Any, strict: bool = ...) -> None: ...
def normalize_name(self, name: Any): ...
def prepare_default(self, value: Any): ...
def normalize_name(self, name: Any) -> str: ...
def prepare_default(self, value: Any) -> Any: ...

View File

@@ -16,6 +16,6 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
sql_create_column_inline_fk: str = ...
sql_delete_fk: str = ...
sql_delete_procedure: str = ...
def quote_value(self, value: Any): ...
def quote_value(self, value: Any) -> str: ...
def add_index(self, model: Any, index: Any, concurrently: bool = ...) -> None: ...
def remove_index(self, model: Any, index: Any, concurrently: bool = ...) -> None: ...

View File

@@ -1,11 +1,13 @@
from collections import namedtuple
from typing import Iterator, Optional, Tuple, Union
from typing import Iterator, Optional, Tuple, Type, Union
from django.db.migrations.state import ModelState, ProjectState
from django.db.models import Field
from django.db.models import Field, Model
from typing_extensions import Literal
def resolve_relation(model, app_label: Optional[str] = ..., model_name: Optional[str] = ...) -> Tuple[str, str]: ...
def resolve_relation(
model: Union[str, Type[Model]], app_label: Optional[str] = ..., model_name: Optional[str] = ...
) -> Tuple[str, str]: ...
FieldReference = namedtuple("FieldReference", ["to", "through"])

View File

@@ -32,9 +32,9 @@ class Model(metaclass=ModelBase):
objects: BaseManager[Any]
pk: Any = ...
_state: ModelState
def __init__(self: _Self, *args, **kwargs) -> None: ...
def __init__(self: _Self, *args: Any, **kwargs: Any) -> None: ...
@classmethod
def add_to_class(cls, name: str, value: Any): ...
def add_to_class(cls, name: str, value: Any) -> Any: ...
@classmethod
def from_db(
cls: Type[_Self], db: Optional[str], field_names: Collection[str], values: Collection[Any]
@@ -59,7 +59,7 @@ class Model(metaclass=ModelBase):
force_update: bool = ...,
using: Optional[str] = ...,
update_fields: Optional[Iterable[str]] = ...,
): ...
) -> None: ...
def refresh_from_db(self: _Self, using: Optional[str] = ..., fields: Optional[Sequence[str]] = ...) -> None: ...
def get_deferred_fields(self) -> Set[str]: ...
@classmethod

View File

@@ -9,7 +9,7 @@ class ChoicesMeta(enum.EnumMeta):
def __contains__(self, member: Any) -> bool: ...
class Choices(enum.Enum, metaclass=ChoicesMeta):
def __str__(self): ...
def __str__(self) -> str: ...
@property
def label(self) -> str: ...
@property

View File

@@ -118,8 +118,21 @@ class F(Combinable):
summarize: bool = ...,
for_save: bool = ...,
) -> F: ...
def asc(self, **kwargs) -> OrderBy: ...
def desc(self, **kwargs) -> OrderBy: ...
def asc(
self,
*,
expression: Union[Expression, F, Subquery],
descending: bool = ...,
nulls_first: bool = ...,
nulls_last: bool = ...,
) -> OrderBy: ...
def desc(
self,
*,
expression: Union[Expression, F, Subquery],
nulls_first: bool = ...,
nulls_last: bool = ...,
) -> OrderBy: ...
def deconstruct(self) -> Any: ... # fake
class ResolvedOuterRef(F): ...

View File

@@ -203,7 +203,9 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
def get_db_prep_save(self, value: Any, connection: BaseDatabaseWrapper) -> Any: ...
def get_internal_type(self) -> str: ...
# TODO: plugin support
def formfield(self, form_class: Optional[Any] = ..., choices_form_class: Optional[Any] = ..., **kwargs) -> Any: ...
def formfield(
self, form_class: Optional[Any] = ..., choices_form_class: Optional[Any] = ..., **kwargs: Any
) -> Any: ...
def save_form_data(self, instance: Model, data: Any) -> None: ...
def contribute_to_class(self, cls: Type[Model], name: str, private_only: bool = ...) -> None: ...
def to_python(self, value: Any) -> Any: ...

View File

@@ -76,4 +76,4 @@ class KeyTransformGte(KeyTransformNumericLookupMixin, lookups.GreaterThanOrEqual
class KeyTransformFactory:
key_name: Any = ...
def __init__(self, key_name: Any) -> None: ...
def __call__(self, *args: Any, **kwargs: Any): ...
def __call__(self, *args: Any, **kwargs: Any) -> KeyTransform: ...

View File

@@ -6,6 +6,7 @@ from django.db.models.fields import Field
from django.db.models.fields.mixins import FieldCacheMixin
from django.db.models.fields.related import ForeignKey, ManyToManyField, OneToOneField, RelatedField
from django.db.models.fields.reverse_related import ManyToManyRel, ManyToOneRel, OneToOneRel
from django.db.models.manager import RelatedManager
from django.db.models.query import QuerySet
from django.db.models.query_utils import DeferredAttribute
@@ -56,11 +57,11 @@ class ReverseManyToOneDescriptor:
field: ForeignKey = ...
def __init__(self, rel: ManyToOneRel) -> None: ...
@property
def related_manager_cls(self): ...
def related_manager_cls(self) -> Type[RelatedManager]: ...
def __get__(self, instance: Optional[Model], cls: Optional[Type[Model]] = ...) -> ReverseManyToOneDescriptor: ...
def __set__(self, instance: Model, value: List[Model]) -> Any: ...
def create_reverse_many_to_one_manager(superclass: Type, rel: Any): ...
def create_reverse_many_to_one_manager(superclass: Type, rel: Any) -> Type[RelatedManager]: ...
class ManyToManyDescriptor(ReverseManyToOneDescriptor):
field: ManyToManyField # type: ignore[assignment]
@@ -70,7 +71,7 @@ class ManyToManyDescriptor(ReverseManyToOneDescriptor):
@property
def through(self) -> Type[Model]: ...
@property
def related_manager_cls(self): ...
def related_manager_cls(self) -> Type[Any]: ... # ManyRelatedManager
# fake
class _ForwardManyToManyManager(Generic[_T]):

View File

@@ -78,7 +78,7 @@ class SQLCompiler:
requested: Optional[Dict[str, Dict[str, Dict[str, Dict[Any, Any]]]]] = ...,
restricted: Optional[bool] = ...,
) -> List[Dict[str, Any]]: ...
def get_select_for_update_of_arguments(self): ...
def get_select_for_update_of_arguments(self) -> List[Any]: ...
def deferred_to_columns(self) -> Dict[Type[Model], Set[str]]: ...
def get_converters(self, expressions: List[Expression]) -> Dict[int, Tuple[List[Callable], Expression]]: ...
def apply_converters(

View File

@@ -27,7 +27,7 @@ class LazyStream:
length: Optional[int] = ...
position: int = ...
def __init__(self, producer: Union[BoundaryIter, ChunkIter], length: Optional[int] = ...) -> None: ...
def tell(self): ...
def tell(self) -> int: ...
def read(self, size: Optional[int] = ...) -> bytes: ...
def __next__(self) -> bytes: ...
def close(self) -> None: ...

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Type, Union
from django.template.defaulttags import TemplateLiteral
@@ -11,10 +11,10 @@ class TokenBase:
second: Any = ...
def nud(self, parser: Any) -> None: ...
def led(self, left: Any, parser: Any) -> None: ...
def display(self): ...
def display(self) -> Any: ...
def infix(bp: Any, func: Any): ...
def prefix(bp: Any, func: Any): ...
def infix(bp: Any, func: Any) -> Type[TokenBase]: ...
def prefix(bp: Any, func: Any) -> Type[TokenBase]: ...
OPERATORS: Any
@@ -23,7 +23,7 @@ class Literal(TokenBase):
lbp: int = ...
value: Optional[_Token] = ...
def __init__(self, value: Optional[_Token]) -> None: ...
def display(self): ...
def display(self) -> str: ...
def eval(self, context: Dict[Any, Any]) -> Optional[_Token]: ...
class EndToken(TokenBase):

View File

@@ -21,7 +21,7 @@ class GetLanguageInfoListNode(Node):
languages: FilterExpression = ...
variable: str = ...
def __init__(self, languages: FilterExpression, variable: str) -> None: ...
def get_language_info(self, language: Any): ...
def get_language_info(self, language: Any) -> Any: ...
def render(self, context: Context) -> str: ...
class GetCurrentLanguageNode(Node):

View File

@@ -45,7 +45,7 @@ class RemoteTestResult:
testsRun: int = ...
def __init__(self) -> None: ...
@property
def test_index(self): ...
def test_index(self) -> int: ...
def check_picklable(self, test: Any, err: Any) -> None: ...
def _confirm_picklable(self, obj: Any) -> None: ...
def check_subtest_picklable(self, test: Any, subtest: Any) -> None: ...
@@ -68,7 +68,7 @@ class RemoteTestRunner:
failfast: bool = ...
buffer: bool = ...
def __init__(self, failfast: bool = ..., resultclass: Optional[Any] = ..., buffer: bool = ...) -> None: ...
def run(self, test: Any): ...
def run(self, test: Any) -> Any: ...
def default_test_processes() -> int: ...
@@ -85,7 +85,7 @@ class ParallelTestSuite(TestSuite):
def __init__(
self, subsuites: List[TestSuite], processes: int, failfast: bool = ..., buffer: bool = ...
) -> None: ...
def run(self, result: Any): ... # type: ignore[override]
def run(self, result: Any) -> Any: ... # type: ignore[override]
class DiscoverRunner:
test_suite: Type[TestSuite] = ...
@@ -166,5 +166,5 @@ def reorder_suite(
def partition_suite_by_type(
suite: TestSuite, classes: Tuple[Type[TestCase], Type[SimpleTestCase]], bins: List[OrderedSet], reverse: bool = ...
) -> None: ...
def partition_suite_by_case(suite: Any): ...
def partition_suite_by_case(suite: Any) -> List[Any]: ...
def filter_tests_by_tags(suite: TestSuite, tags: Set[str], exclude_tags: Set[str]) -> TestSuite: ...

View File

@@ -1,5 +1,5 @@
from contextlib import contextmanager
from typing import Any, Generator
from typing import Any, Generator, Type
from django.test import LiveServerTestCase
@@ -7,8 +7,8 @@ class SeleniumTestCaseBase:
browsers: Any = ...
browser: Any = ...
@classmethod
def import_webdriver(cls, browser: Any): ...
def create_webdriver(self): ...
def import_webdriver(cls, browser: Any) -> Type[Any]: ... # Type[WebDriver]
def create_webdriver(self) -> Any: ... # WebDriver
class SeleniumTestCase(LiveServerTestCase):
implicit_wait: int = ...

View File

@@ -240,16 +240,16 @@ class FSFilesHandler(WSGIHandler):
application: Any = ...
base_url: Any = ...
def __init__(self, application: Any) -> None: ...
def file_path(self, url: Any): ...
def file_path(self, url: Any) -> str: ...
def serve(self, request: Any) -> FileResponse: ...
class _StaticFilesHandler(FSFilesHandler):
def get_base_dir(self): ...
def get_base_url(self): ...
def get_base_dir(self) -> str: ...
def get_base_url(self) -> str: ...
class _MediaFilesHandler(FSFilesHandler):
def get_base_dir(self): ...
def get_base_url(self): ...
def get_base_dir(self) -> str: ...
def get_base_url(self) -> str: ...
class LiveServerThread(threading.Thread):
host: str = ...

View File

@@ -100,7 +100,7 @@ class CaptureQueriesContext:
initial_queries: int = ...
final_queries: Optional[int] = ...
def __init__(self, connection: BaseDatabaseWrapper) -> None: ...
def __iter__(self): ...
def __iter__(self) -> Iterator[Dict[str, str]]: ...
def __getitem__(self, index: int) -> Dict[str, str]: ...
def __len__(self) -> int: ...
@property
@@ -144,13 +144,13 @@ class isolate_apps(TestContextDecorator):
@contextmanager
def extend_sys_path(*paths: str) -> Iterator[None]: ...
@contextmanager
def captured_output(stream_name) -> Iterator[StringIO]: ...
def captured_output(stream_name: str) -> Iterator[StringIO]: ...
def captured_stdin() -> ContextManager: ...
def captured_stdout() -> ContextManager: ...
def captured_stderr() -> ContextManager: ...
@contextmanager
def freeze_time(t: float) -> Iterator[None]: ...
def tag(*tags: str): ...
def tag(*tags: str) -> Callable[[_C], _C]: ...
_Signature = str
_TestDatabase = Tuple[str, List[str]]

View File

@@ -1,3 +1,8 @@
from typing import Any
from typing import Any, Callable, TypeVar, overload
def async_unsafe(message: Any): ...
_C = TypeVar("_C", bound=Callable)
@overload
def async_unsafe(message: str) -> Callable[[_C], _C]: ...
@overload
def async_unsafe(message: _C) -> _C: ...

View File

@@ -6,6 +6,9 @@ from typing import Any, Callable, Dict, FrozenSet, Iterable, Iterator, List, Opt
from django.apps.registry import Apps
from django.dispatch import Signal
from django.utils._os import _PathCompatible
from typing_extensions import ParamSpec
_P = ParamSpec("_P")
autoreload_started: Signal
file_changed: Signal
@@ -13,7 +16,7 @@ DJANGO_AUTORELOAD_ENV: str
def is_django_module(module: types.ModuleType) -> bool: ...
def is_django_path(path: _PathCompatible) -> bool: ...
def check_errors(fn) -> Callable[..., None]: ...
def check_errors(fn: Callable[_P, Any]) -> Callable[_P, None]: ...
def raise_last_exception() -> None: ...
def ensure_echo_on() -> None: ...
def iter_all_python_module_files() -> Set[Path]: ...

View File

@@ -37,20 +37,20 @@ class DateFormat(TimeFormat):
timezone: Optional[_TzInfoT]
year_days: Any = ...
def __init__(self, obj: Union[builtin_datetime, builtin_time, date]) -> None: ...
def b(self): ...
def b(self) -> str: ...
def c(self) -> str: ...
def d(self) -> str: ...
def D(self): ...
def E(self): ...
def F(self): ...
def D(self) -> str: ...
def E(self) -> str: ...
def F(self) -> str: ...
def I(self) -> str: ...
def j(self) -> int: ...
def l(self): ...
def l(self) -> str: ...
def L(self) -> bool: ...
def m(self) -> str: ...
def M(self) -> str: ...
def n(self) -> int: ...
def N(self): ...
def N(self) -> str: ...
def o(self) -> int: ...
def r(self) -> str: ...
def S(self) -> str: ...

View File

@@ -20,12 +20,12 @@ class warn_about_renamed_method:
class RenameMethodsBase(type):
renamed_methods: Any = ...
def __new__(cls, name: Any, bases: Any, attrs: Any): ...
def __new__(cls, name: Any, bases: Any, attrs: Any) -> Type: ...
class DeprecationInstanceCheck(type):
alternative: str
deprecation_warning: Type[Warning]
def __instancecheck__(self, instance: Any): ...
def __instancecheck__(self, instance: Any) -> bool: ...
class GetResponseCallable(Protocol):
def __call__(self, __request: HttpRequest) -> HttpResponse: ...

View File

@@ -45,7 +45,7 @@ class SyndicationFeed:
enclosures: Optional[List[Enclosure]] = ...,
**kwargs: Any
) -> None: ...
def num_items(self): ...
def num_items(self) -> int: ...
def root_attributes(self) -> Dict[Any, Any]: ...
def add_root_elements(self, handler: ContentHandler) -> None: ...
def item_attributes(self, item: Dict[str, Any]) -> Dict[Any, Any]: ...

View File

@@ -24,7 +24,7 @@ class Promise:
def __mod__(self, rhs: Any) -> Any: ...
def __add__(self, other: Any) -> Any: ...
def __radd__(self, other: Any) -> Any: ...
def __deepcopy__(self, memo: Any): ...
def __deepcopy__(self: _T, memo: Any) -> _T: ...
class _StrPromise(Promise, Sequence[str]):
def __add__(self, __s: str) -> str: ...

View File

@@ -24,7 +24,7 @@ class Trans:
ngettext: Callable
npgettext: Callable
pgettext: Callable
def __getattr__(self, real_name: Any): ...
def __getattr__(self, real_name: Any) -> Any: ...
def gettext_noop(message: str) -> str: ...
def gettext(message: str) -> str: ...

View File

@@ -2,7 +2,7 @@ from typing import Any
from django.http.request import HttpRequest
def gettext(message: Any): ...
def gettext(message: str) -> str: ...
gettext_noop = gettext
gettext_lazy = gettext
@@ -12,14 +12,14 @@ def ngettext(singular: str, plural: str, number: int) -> str: ...
ngettext_lazy = ngettext
def pgettext(context: Any, message: Any): ...
def npgettext(context: Any, singular: Any, plural: Any, number: Any): ...
def activate(x: Any): ...
def deactivate(): ...
def pgettext(context: str, message: str) -> str: ...
def npgettext(context: str, singular: str, plural: str, number: int) -> str: ...
def activate(x: str) -> None: ...
def deactivate() -> None: ...
deactivate_all = deactivate
def get_language(): ...
def get_language() -> str: ...
def get_language_bidi() -> bool: ...
def check_for_language(x: str) -> bool: ...
def get_language_from_request(request: HttpRequest, check_path: bool = ...) -> str: ...

View File

@@ -1,7 +1,7 @@
from importlib.abc import SourceLoader
from pathlib import Path
from types import TracebackType
from typing import Any, Callable, Dict, Iterator, List, Optional, Type, Union
from typing import Any, Callable, Dict, ItemsView, Iterator, List, Optional, Type, Union
from django.http.request import HttpRequest, QueryDict
from django.http.response import Http404, HttpResponse
@@ -13,7 +13,9 @@ CURRENT_DIR: Path
class CallableSettingWrapper:
def __init__(self, callable_setting: Union[Callable, Type[Any]]) -> None: ...
def technical_500_response(request: Any, exc_type: Any, exc_value: Any, tb: Any, status_code: int = ...): ...
def technical_500_response(
request: Any, exc_type: Any, exc_value: Any, tb: Any, status_code: int = ...
) -> HttpResponse: ...
def get_default_exception_reporter_filter() -> SafeExceptionReporterFilter: ...
def get_exception_reporter_filter(request: Optional[HttpRequest]) -> SafeExceptionReporterFilter: ...
@@ -24,7 +26,7 @@ class SafeExceptionReporterFilter:
def get_cleansed_multivaluedict(self, request: HttpRequest, multivaluedict: QueryDict) -> QueryDict: ...
def get_post_parameters(self, request: Optional[HttpRequest]) -> Dict[str, Any]: ...
def cleanse_special_types(self, request: Optional[HttpRequest], value: Any) -> Any: ...
def get_traceback_frame_variables(self, request: Any, tb_frame: Any): ...
def get_traceback_frame_variables(self, request: Any, tb_frame: Any) -> ItemsView[str, Any]: ...
class ExceptionReporter:
request: Optional[HttpRequest] = ...
@@ -55,14 +57,6 @@ class ExceptionReporter:
def get_exception_traceback_frames(
self, exc_value: Optional[BaseException], tb: Optional[TracebackType]
) -> Iterator[Dict[str, Any]]: ...
def _get_lines_from_file(
self,
filename: str,
lineno: int,
context_lines: int,
loader: Optional[SourceLoader] = ...,
module_name: Optional[str] = ...,
): ...
def technical_404_response(request: HttpRequest, exception: Http404) -> HttpResponse: ...
def default_urlconf(request: Optional[HttpResponse]) -> HttpResponse: ...

View File

@@ -1,6 +1,6 @@
from typing import Any, Optional
from django.http import FileResponse
from django.http import FileResponse, HttpResponse
from django.http.request import HttpRequest
def serve(
@@ -10,5 +10,5 @@ def serve(
DEFAULT_DIRECTORY_INDEX_TEMPLATE: str
template_translatable: Any
def directory_index(path: Any, fullpath: Any): ...
def directory_index(path: Any, fullpath: Any) -> HttpResponse: ...
def was_modified_since(header: Optional[str] = ..., mtime: float = ..., size: int = ...) -> bool: ...