From 36044c98b8851eae70b58160c8214e8e60bd2e95 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Fri, 28 Oct 2022 13:08:00 +0300 Subject: [PATCH] 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 --- django-stubs/conf/global_settings.pyi | 2 +- django-stubs/contrib/admin/checks.pyi | 18 +++++++------- django-stubs/contrib/admin/helpers.pyi | 4 ++-- django-stubs/contrib/admin/options.pyi | 14 ++++++++--- django-stubs/contrib/admin/utils.pyi | 8 +++++-- django-stubs/contrib/admindocs/utils.pyi | 8 ++++--- django-stubs/contrib/admindocs/views.pyi | 2 +- django-stubs/contrib/auth/backends.pyi | 3 ++- django-stubs/contrib/auth/models.pyi | 3 ++- django-stubs/contrib/auth/views.pyi | 4 ++-- django-stubs/contrib/contenttypes/fields.pyi | 2 +- django-stubs/contrib/contenttypes/forms.pyi | 22 ++++++++++------- .../contrib/gis/db/backends/base/features.pyi | 24 +++++++++---------- .../gis/db/backends/spatialite/features.pyi | 2 +- .../gis/db/backends/spatialite/operations.pyi | 4 ++-- .../contrib/messages/storage/base.pyi | 6 ++--- .../contrib/postgres/fields/hstore.pyi | 6 ++--- django-stubs/contrib/postgres/serializers.pyi | 4 +++- django-stubs/contrib/postgres/utils.pyi | 4 +++- django-stubs/core/cache/__init__.pyi | 4 ++-- .../core/cache/backends/memcached.pyi | 15 +++++++++--- django-stubs/core/management/__init__.pyi | 2 +- .../core/management/commands/sqlmigrate.pyi | 4 ++-- django-stubs/core/serializers/pyyaml.pyi | 5 ++-- django-stubs/db/backends/base/creation.pyi | 4 ++-- django-stubs/db/backends/base/operations.pyi | 6 ++--- django-stubs/db/backends/base/schema.pyi | 6 ++--- django-stubs/db/backends/ddl_references.pyi | 4 ++-- django-stubs/db/backends/mysql/base.pyi | 14 +++++------ django-stubs/db/backends/mysql/compiler.pyi | 2 +- django-stubs/db/backends/mysql/schema.pyi | 8 +++---- django-stubs/db/backends/oracle/schema.pyi | 6 ++--- .../db/backends/postgresql/schema.pyi | 2 +- .../db/migrations/operations/utils.pyi | 8 ++++--- django-stubs/db/models/base.pyi | 6 ++--- django-stubs/db/models/enums.pyi | 2 +- django-stubs/db/models/expressions.pyi | 17 +++++++++++-- django-stubs/db/models/fields/__init__.pyi | 4 +++- django-stubs/db/models/fields/json.pyi | 2 +- .../db/models/fields/related_descriptors.pyi | 7 +++--- django-stubs/db/models/sql/compiler.pyi | 2 +- django-stubs/http/multipartparser.pyi | 2 +- django-stubs/template/smartif.pyi | 10 ++++---- django-stubs/templatetags/i18n.pyi | 2 +- django-stubs/test/runner.pyi | 8 +++---- django-stubs/test/selenium.pyi | 6 ++--- django-stubs/test/testcases.pyi | 10 ++++---- django-stubs/test/utils.pyi | 6 ++--- django-stubs/utils/asyncio.pyi | 9 +++++-- django-stubs/utils/autoreload.pyi | 5 +++- django-stubs/utils/dateformat.pyi | 12 +++++----- django-stubs/utils/deprecation.pyi | 4 ++-- django-stubs/utils/feedgenerator.pyi | 2 +- django-stubs/utils/functional.pyi | 2 +- django-stubs/utils/translation/__init__.pyi | 2 +- django-stubs/utils/translation/trans_null.pyi | 12 +++++----- django-stubs/views/debug.pyi | 16 ++++--------- django-stubs/views/static.pyi | 4 ++-- 58 files changed, 218 insertions(+), 164 deletions(-) diff --git a/django-stubs/conf/global_settings.pyi b/django-stubs/conf/global_settings.pyi index 2778e8e..d66ccf9 100644 --- a/django-stubs/conf/global_settings.pyi +++ b/django-stubs/conf/global_settings.pyi @@ -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]] = ... diff --git a/django-stubs/contrib/admin/checks.pyi b/django-stubs/contrib/admin/checks.pyi index 654079f..c44ff93 100644 --- a/django-stubs/contrib/admin/checks.pyi +++ b/django-stubs/contrib/admin/checks.pyi @@ -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]: ... diff --git a/django-stubs/contrib/admin/helpers.pyi b/django-stubs/contrib/admin/helpers.pyi index 6753005..19b2f37 100644 --- a/django-stubs/contrib/admin/helpers.pyi +++ b/django-stubs/contrib/admin/helpers.pyi @@ -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 = ... diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 9cc1a38..34d6255 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -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, diff --git a/django-stubs/contrib/admin/utils.pyi b/django-stubs/contrib/admin/utils.pyi index 0c89f68..d616206 100644 --- a/django-stubs/contrib/admin/utils.pyi +++ b/django-stubs/contrib/admin/utils.pyi @@ -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] = ... diff --git a/django-stubs/contrib/admindocs/utils.pyi b/django-stubs/contrib/admindocs/utils.pyi index 9fb7671..63cec51 100644 --- a/django-stubs/contrib/admindocs/utils.pyi +++ b/django-stubs/contrib/admindocs/utils.pyi @@ -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 diff --git a/django-stubs/contrib/admindocs/views.pyi b/django-stubs/contrib/admindocs/views.pyi index 60fa6cc..98be0da 100644 --- a/django-stubs/contrib/admindocs/views.pyi +++ b/django-stubs/contrib/admindocs/views.pyi @@ -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] = ... diff --git a/django-stubs/contrib/auth/backends.pyi b/django-stubs/contrib/auth/backends.pyi index e831ae2..6c9cb06 100644 --- a/django-stubs/contrib/auth/backends.pyi +++ b/django-stubs/contrib/auth/backends.pyi @@ -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): ... diff --git a/django-stubs/contrib/auth/models.pyi b/django-stubs/contrib/auth/models.pyi index 46d7b0f..0ddfb6d 100644 --- a/django-stubs/contrib/auth/models.pyi +++ b/django-stubs/contrib/auth/models.pyi @@ -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() diff --git a/django-stubs/contrib/auth/views.pyi b/django-stubs/contrib/auth/views.pyi index c24a85d..f1ada82 100644 --- a/django-stubs/contrib/auth/views.pyi +++ b/django-stubs/contrib/auth/views.pyi @@ -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 = ... diff --git a/django-stubs/contrib/contenttypes/fields.pyi b/django-stubs/contrib/contenttypes/fields.pyi index 399a270..b3617f3 100644 --- a/django-stubs/contrib/contenttypes/fields.pyi +++ b/django-stubs/contrib/contenttypes/fields.pyi @@ -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 diff --git a/django-stubs/contrib/contenttypes/forms.pyi b/django-stubs/contrib/contenttypes/forms.pyi index a8db225..ff87985 100644 --- a/django-stubs/contrib/contenttypes/forms.pyi +++ b/django-stubs/contrib/contenttypes/forms.pyi @@ -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]]: ... diff --git a/django-stubs/contrib/gis/db/backends/base/features.pyi b/django-stubs/contrib/gis/db/backends/base/features.pyi index 9f334a2..6bb87ce 100644 --- a/django-stubs/contrib/gis/db/backends/base/features.pyi +++ b/django-stubs/contrib/gis/db/backends/base/features.pyi @@ -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: ... diff --git a/django-stubs/contrib/gis/db/backends/spatialite/features.pyi b/django-stubs/contrib/gis/db/backends/spatialite/features.pyi index b0cd52e..e4680b1 100644 --- a/django-stubs/contrib/gis/db/backends/spatialite/features.pyi +++ b/django-stubs/contrib/gis/db/backends/spatialite/features.pyi @@ -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] diff --git a/django-stubs/contrib/gis/db/backends/spatialite/operations.pyi b/django-stubs/contrib/gis/db/backends/spatialite/operations.pyi index a12ab8b..1c3c0bf 100644 --- a/django-stubs/contrib/gis/db/backends/spatialite/operations.pyi +++ b/django-stubs/contrib/gis/db/backends/spatialite/operations.pyi @@ -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: ... diff --git a/django-stubs/contrib/messages/storage/base.pyi b/django-stubs/contrib/messages/storage/base.pyi index d6a7163..01ccca8 100644 --- a/django-stubs/contrib/messages/storage/base.pyi +++ b/django-stubs/contrib/messages/storage/base.pyi @@ -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 = ... diff --git a/django-stubs/contrib/postgres/fields/hstore.pyi b/django-stubs/contrib/postgres/fields/hstore.pyi index 5d0350c..700b4d2 100644 --- a/django-stubs/contrib/postgres/fields/hstore.pyi +++ b/django-stubs/contrib/postgres/fields/hstore.pyi @@ -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): ... diff --git a/django-stubs/contrib/postgres/serializers.pyi b/django-stubs/contrib/postgres/serializers.pyi index 9de9402..3e3c1d5 100644 --- a/django-stubs/contrib/postgres/serializers.pyi +++ b/django-stubs/contrib/postgres/serializers.pyi @@ -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]]: ... diff --git a/django-stubs/contrib/postgres/utils.pyi b/django-stubs/contrib/postgres/utils.pyi index 2dec306..0919dd6 100644 --- a/django-stubs/contrib/postgres/utils.pyi +++ b/django-stubs/contrib/postgres/utils.pyi @@ -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: ... diff --git a/django-stubs/core/cache/__init__.pyi b/django-stubs/core/cache/__init__.pyi index 52eacf6..fe327d7 100644 --- a/django-stubs/core/cache/__init__.pyi +++ b/django-stubs/core/cache/__init__.pyi @@ -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: ... diff --git a/django-stubs/core/cache/backends/memcached.pyi b/django-stubs/core/cache/backends/memcached.pyi index ef875a2..3956df3 100644 --- a/django-stubs/core/cache/backends/memcached.pyi +++ b/django-stubs/core/cache/backends/memcached.pyi @@ -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: ... diff --git a/django-stubs/core/management/__init__.pyi b/django-stubs/core/management/__init__.pyi index 5c84657..beadeed 100644 --- a/django-stubs/core/management/__init__.pyi +++ b/django-stubs/core/management/__init__.pyi @@ -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: ... diff --git a/django-stubs/core/management/commands/sqlmigrate.pyi b/django-stubs/core/management/commands/sqlmigrate.pyi index febeff5..0bae1d9 100644 --- a/django-stubs/core/management/commands/sqlmigrate.pyi +++ b/django-stubs/core/management/commands/sqlmigrate.pyi @@ -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]: ... diff --git a/django-stubs/core/serializers/pyyaml.pyi b/django-stubs/core/serializers/pyyaml.pyi index 9ee0eab..3cb695b 100644 --- a/django-stubs/core/serializers/pyyaml.pyi +++ b/django-stubs/core/serializers/pyyaml.pyi @@ -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 = ... diff --git a/django-stubs/db/backends/base/creation.pyi b/django-stubs/db/backends/base/creation.pyi index af249d0..95767f9 100644 --- a/django-stubs/db/backends/base/creation.pyi +++ b/django-stubs/db/backends/base/creation.pyi @@ -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]: ... diff --git a/django-stubs/db/backends/base/operations.pyi b/django-stubs/db/backends/base/operations.pyi index 8031221..9d0778b 100644 --- a/django-stubs/db/backends/base/operations.pyi +++ b/django-stubs/db/backends/base/operations.pyi @@ -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]: ... diff --git a/django-stubs/db/backends/base/schema.pyi b/django-stubs/db/backends/base/schema.pyi index 6bc2dae..b4ddba2 100644 --- a/django-stubs/db/backends/base/schema.pyi +++ b/django-stubs/db/backends/base/schema.pyi @@ -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: ... diff --git a/django-stubs/db/backends/ddl_references.pyi b/django-stubs/db/backends/ddl_references.pyi index c0ae483..91a32d7 100644 --- a/django-stubs/db/backends/ddl_references.pyi +++ b/django-stubs/db/backends/ddl_references.pyi @@ -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: ... diff --git a/django-stubs/db/backends/mysql/base.pyi b/django-stubs/db/backends/mysql/base.pyi index e69f804..3761e10 100644 --- a/django-stubs/db/backends/mysql/base.pyi +++ b/django-stubs/db/backends/mysql/base.pyi @@ -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: ... diff --git a/django-stubs/db/backends/mysql/compiler.pyi b/django-stubs/db/backends/mysql/compiler.pyi index 54f03b5..dad64f2 100644 --- a/django-stubs/db/backends/mysql/compiler.pyi +++ b/django-stubs/db/backends/mysql/compiler.pyi @@ -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): ... diff --git a/django-stubs/db/backends/mysql/schema.pyi b/django-stubs/db/backends/mysql/schema.pyi index acf0f27..474d016 100644 --- a/django-stubs/db/backends/mysql/schema.pyi +++ b/django-stubs/db/backends/mysql/schema.pyi @@ -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: ... diff --git a/django-stubs/db/backends/oracle/schema.pyi b/django-stubs/db/backends/oracle/schema.pyi index 2548418..f022ebe 100644 --- a/django-stubs/db/backends/oracle/schema.pyi +++ b/django-stubs/db/backends/oracle/schema.pyi @@ -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: ... diff --git a/django-stubs/db/backends/postgresql/schema.pyi b/django-stubs/db/backends/postgresql/schema.pyi index 7ea53fd..0dc32ef 100644 --- a/django-stubs/db/backends/postgresql/schema.pyi +++ b/django-stubs/db/backends/postgresql/schema.pyi @@ -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: ... diff --git a/django-stubs/db/migrations/operations/utils.pyi b/django-stubs/db/migrations/operations/utils.pyi index 666385d..2d9a01c 100644 --- a/django-stubs/db/migrations/operations/utils.pyi +++ b/django-stubs/db/migrations/operations/utils.pyi @@ -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"]) diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index 791c376..9c189d5 100644 --- a/django-stubs/db/models/base.pyi +++ b/django-stubs/db/models/base.pyi @@ -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 diff --git a/django-stubs/db/models/enums.pyi b/django-stubs/db/models/enums.pyi index 4370f59..83bde05 100644 --- a/django-stubs/db/models/enums.pyi +++ b/django-stubs/db/models/enums.pyi @@ -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 diff --git a/django-stubs/db/models/expressions.pyi b/django-stubs/db/models/expressions.pyi index f7c838e..f3d2f32 100644 --- a/django-stubs/db/models/expressions.pyi +++ b/django-stubs/db/models/expressions.pyi @@ -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): ... diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index a7be5fb..cb5c0c2 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -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: ... diff --git a/django-stubs/db/models/fields/json.pyi b/django-stubs/db/models/fields/json.pyi index 5aacf54..36b03b2 100644 --- a/django-stubs/db/models/fields/json.pyi +++ b/django-stubs/db/models/fields/json.pyi @@ -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: ... diff --git a/django-stubs/db/models/fields/related_descriptors.pyi b/django-stubs/db/models/fields/related_descriptors.pyi index f5f7fc0..9cc56a8 100644 --- a/django-stubs/db/models/fields/related_descriptors.pyi +++ b/django-stubs/db/models/fields/related_descriptors.pyi @@ -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]): diff --git a/django-stubs/db/models/sql/compiler.pyi b/django-stubs/db/models/sql/compiler.pyi index 80fe68a..adbbf01 100644 --- a/django-stubs/db/models/sql/compiler.pyi +++ b/django-stubs/db/models/sql/compiler.pyi @@ -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( diff --git a/django-stubs/http/multipartparser.pyi b/django-stubs/http/multipartparser.pyi index e157729..28ddab7 100644 --- a/django-stubs/http/multipartparser.pyi +++ b/django-stubs/http/multipartparser.pyi @@ -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: ... diff --git a/django-stubs/template/smartif.pyi b/django-stubs/template/smartif.pyi index a60d2fa..8bce5f3 100644 --- a/django-stubs/template/smartif.pyi +++ b/django-stubs/template/smartif.pyi @@ -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): diff --git a/django-stubs/templatetags/i18n.pyi b/django-stubs/templatetags/i18n.pyi index 6c3884a..432525c 100644 --- a/django-stubs/templatetags/i18n.pyi +++ b/django-stubs/templatetags/i18n.pyi @@ -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): diff --git a/django-stubs/test/runner.pyi b/django-stubs/test/runner.pyi index 718601b..22ba19b 100644 --- a/django-stubs/test/runner.pyi +++ b/django-stubs/test/runner.pyi @@ -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: ... diff --git a/django-stubs/test/selenium.pyi b/django-stubs/test/selenium.pyi index 7566339..f87f8bb 100644 --- a/django-stubs/test/selenium.pyi +++ b/django-stubs/test/selenium.pyi @@ -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 = ... diff --git a/django-stubs/test/testcases.pyi b/django-stubs/test/testcases.pyi index 5459253..ee729e4 100644 --- a/django-stubs/test/testcases.pyi +++ b/django-stubs/test/testcases.pyi @@ -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 = ... diff --git a/django-stubs/test/utils.pyi b/django-stubs/test/utils.pyi index df4f97e..f318b71 100644 --- a/django-stubs/test/utils.pyi +++ b/django-stubs/test/utils.pyi @@ -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]] diff --git a/django-stubs/utils/asyncio.pyi b/django-stubs/utils/asyncio.pyi index 8a9a62d..7e6c55e 100644 --- a/django-stubs/utils/asyncio.pyi +++ b/django-stubs/utils/asyncio.pyi @@ -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: ... diff --git a/django-stubs/utils/autoreload.pyi b/django-stubs/utils/autoreload.pyi index ba2a83a..e1031fe 100644 --- a/django-stubs/utils/autoreload.pyi +++ b/django-stubs/utils/autoreload.pyi @@ -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]: ... diff --git a/django-stubs/utils/dateformat.pyi b/django-stubs/utils/dateformat.pyi index 274060b..9b6919b 100644 --- a/django-stubs/utils/dateformat.pyi +++ b/django-stubs/utils/dateformat.pyi @@ -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: ... diff --git a/django-stubs/utils/deprecation.pyi b/django-stubs/utils/deprecation.pyi index 77e61a8..366dbc8 100644 --- a/django-stubs/utils/deprecation.pyi +++ b/django-stubs/utils/deprecation.pyi @@ -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: ... diff --git a/django-stubs/utils/feedgenerator.pyi b/django-stubs/utils/feedgenerator.pyi index f1f0249..0978548 100644 --- a/django-stubs/utils/feedgenerator.pyi +++ b/django-stubs/utils/feedgenerator.pyi @@ -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]: ... diff --git a/django-stubs/utils/functional.pyi b/django-stubs/utils/functional.pyi index e45c3d4..83ff039 100644 --- a/django-stubs/utils/functional.pyi +++ b/django-stubs/utils/functional.pyi @@ -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: ... diff --git a/django-stubs/utils/translation/__init__.pyi b/django-stubs/utils/translation/__init__.pyi index 4b1bbb4..fbdc872 100644 --- a/django-stubs/utils/translation/__init__.pyi +++ b/django-stubs/utils/translation/__init__.pyi @@ -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: ... diff --git a/django-stubs/utils/translation/trans_null.pyi b/django-stubs/utils/translation/trans_null.pyi index 6ea5a34..2eb12c6 100644 --- a/django-stubs/utils/translation/trans_null.pyi +++ b/django-stubs/utils/translation/trans_null.pyi @@ -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: ... diff --git a/django-stubs/views/debug.pyi b/django-stubs/views/debug.pyi index 9f4f66b..8e4af92 100644 --- a/django-stubs/views/debug.pyi +++ b/django-stubs/views/debug.pyi @@ -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: ... diff --git a/django-stubs/views/static.pyi b/django-stubs/views/static.pyi index 80d1943..f27674a 100644 --- a/django-stubs/views/static.pyi +++ b/django-stubs/views/static.pyi @@ -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: ...