From a13d4c352a09491f5508f27ebea6a89515c2d054 Mon Sep 17 00:00:00 2001 From: Maxim Kurnikov Date: Tue, 14 Aug 2018 12:01:01 +0300 Subject: [PATCH] fifth iteration --- django-stubs/conf/urls/__init__.pyi | 15 +- django-stubs/contrib/admin/filters.pyi | 18 +- django-stubs/contrib/admin/helpers.pyi | 7 +- django-stubs/contrib/admin/options.pyi | 28 +- .../contrib/admin/templatetags/admin_list.pyi | 5 +- django-stubs/contrib/admin/utils.pyi | 60 +- django-stubs/contrib/admin/views/main.pyi | 6 +- django-stubs/contrib/admin/widgets.pyi | 147 +- django-stubs/contrib/auth/admin.pyi | 14 +- .../contrib/auth/context_processors.pyi | 5 +- django-stubs/contrib/auth/forms.pyi | 19 +- .../contrib/auth/password_validation.pyi | 8 +- django-stubs/contrib/auth/views.pyi | 16 +- django-stubs/contrib/contenttypes/fields.pyi | 4 +- .../contrib/messages/context_processors.pyi | 5 +- .../contrib/messages/storage/cookie.pyi | 18 - .../contrib/postgres/fields/array.pyi | 6 +- .../contrib/sessions/backends/base.pyi | 23 +- django-stubs/contrib/sessions/backends/db.pyi | 12 +- django-stubs/contrib/sessions/serializers.pyi | 11 +- django-stubs/contrib/sitemaps/__init__.pyi | 5 +- django-stubs/contrib/sitemaps/views.pyi | 7 +- .../management/commands/collectstatic.pyi | 19 +- django-stubs/contrib/staticfiles/utils.pyi | 4 +- django-stubs/core/cache/__init__.pyi | 3 +- django-stubs/core/cache/backends/base.pyi | 15 +- django-stubs/core/cache/backends/db.pyi | 7 +- .../core/cache/backends/filebased.pyi | 7 +- django-stubs/core/cache/backends/locmem.pyi | 13 +- django-stubs/core/exceptions.pyi | 8 +- .../core/management/commands/inspectdb.pyi | 8 +- .../core/management/commands/loaddata.pyi | 2 +- django-stubs/core/serializers/__init__.pyi | 10 +- django-stubs/core/serializers/base.pyi | 18 +- django-stubs/core/serializers/json.pyi | 6 +- django-stubs/core/serializers/python.pyi | 75 +- django-stubs/db/backends/base/base.pyi | 6 +- django-stubs/db/backends/base/operations.pyi | 23 +- django-stubs/db/backends/base/schema.pyi | 4 +- django-stubs/db/backends/mysql/client.pyi | 9 +- django-stubs/db/backends/sqlite3/base.pyi | 7 +- .../db/backends/sqlite3/introspection.pyi | 8 +- .../db/backends/sqlite3/operations.pyi | 6 +- django-stubs/db/backends/sqlite3/schema.pyi | 4 +- django-stubs/db/backends/utils.pyi | 7 +- django-stubs/db/migrations/autodetector.pyi | 19 +- django-stubs/db/migrations/executor.pyi | 6 +- django-stubs/db/migrations/loader.pyi | 8 +- .../db/migrations/operations/base.pyi | 4 +- .../db/migrations/operations/models.pyi | 5 +- django-stubs/db/migrations/recorder.pyi | 4 +- django-stubs/db/migrations/state.pyi | 23 +- django-stubs/db/models/aggregates.pyi | 4 +- django-stubs/db/models/base.pyi | 46 +- django-stubs/db/models/expressions.pyi | 99 +- django-stubs/db/models/fields/__init__.pyi | 192 +-- django-stubs/db/models/fields/files.pyi | 20 +- django-stubs/db/models/fields/related.pyi | 105 +- .../db/models/fields/related_lookups.pyi | 19 +- .../db/models/fields/reverse_related.pyi | 8 +- .../db/models/functions/comparison.pyi | 2 +- django-stubs/db/models/functions/datetime.pyi | 17 +- django-stubs/db/models/functions/text.pyi | 2 +- django-stubs/db/models/lookups.pyi | 113 +- django-stubs/db/models/manager.pyi | 14 +- django-stubs/db/models/options.pyi | 9 +- django-stubs/db/models/query.pyi | 285 ++-- django-stubs/db/models/query_utils.pyi | 52 +- django-stubs/db/models/sql/compiler.pyi | 291 ++-- django-stubs/db/models/sql/datastructures.pyi | 4 +- django-stubs/db/models/sql/query.pyi | 96 +- django-stubs/db/models/sql/subqueries.pyi | 48 +- django-stubs/db/models/sql/where.pyi | 82 +- django-stubs/db/utils.pyi | 18 +- django-stubs/dispatch/dispatcher.pyi | 2 +- django-stubs/forms/fields.pyi | 92 +- django-stubs/forms/forms.pyi | 34 +- django-stubs/forms/formsets.pyi | 4 +- django-stubs/forms/models.pyi | 127 +- django-stubs/forms/renderers.pyi | 721 +--------- django-stubs/forms/utils.pyi | 10 +- django-stubs/forms/widgets.pyi | 1258 +++-------------- django-stubs/http/multipartparser.pyi | 14 +- django-stubs/http/request.pyi | 4 +- django-stubs/http/response.pyi | 1 - django-stubs/middleware/cache.pyi | 10 +- django-stubs/middleware/csrf.pyi | 20 +- django-stubs/shortcuts.pyi | 10 +- django-stubs/template/backends/django.pyi | 861 +---------- django-stubs/template/backends/jinja2.pyi | 392 +---- django-stubs/template/base.pyi | 24 +- django-stubs/template/context.pyi | 141 +- django-stubs/template/defaultfilters.pyi | 25 +- django-stubs/template/defaulttags.pyi | 40 +- django-stubs/template/engine.pyi | 113 +- django-stubs/template/library.pyi | 7 +- django-stubs/template/loader.pyi | 14 +- django-stubs/template/loaders/cached.pyi | 17 +- django-stubs/template/response.pyi | 188 +-- django-stubs/templatetags/l10n.pyi | 8 +- django-stubs/test/client.pyi | 93 +- django-stubs/test/testcases.pyi | 34 +- django-stubs/test/utils.pyi | 147 +- django-stubs/urls/base.pyi | 7 +- django-stubs/urls/conf.pyi | 7 +- django-stubs/urls/resolvers.pyi | 113 +- django-stubs/utils/autoreload.pyi | 6 +- django-stubs/utils/cache.pyi | 9 +- django-stubs/utils/datastructures.pyi | 43 +- django-stubs/utils/dateformat.pyi | 12 +- django-stubs/utils/deconstruct.pyi | 7 +- django-stubs/utils/decorators.pyi | 31 +- django-stubs/utils/feedgenerator.pyi | 36 +- django-stubs/utils/formats.pyi | 9 +- django-stubs/utils/http.pyi | 20 +- django-stubs/utils/itercompat.pyi | 21 +- django-stubs/utils/regex_helper.pyi | 4 +- django-stubs/utils/timezone.pyi | 4 +- django-stubs/utils/tree.pyi | 30 +- django-stubs/views/debug.pyi | 2 +- django-stubs/views/generic/base.pyi | 30 +- django-stubs/views/generic/detail.pyi | 9 +- django-stubs/views/generic/edit.pyi | 7 +- django-stubs/views/generic/list.pyi | 15 +- 124 files changed, 1455 insertions(+), 5681 deletions(-) diff --git a/django-stubs/conf/urls/__init__.pyi b/django-stubs/conf/urls/__init__.pyi index e0574ef..1fd317d 100644 --- a/django-stubs/conf/urls/__init__.pyi +++ b/django-stubs/conf/urls/__init__.pyi @@ -1,5 +1,7 @@ -from typing import Any, Callable, Dict, Optional, Tuple, Type, Union +from collections import OrderedDict +from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union +from django.contrib.flatpages.sitemaps import FlatPageSitemap from django.contrib.sitemaps import Sitemap from django.urls import include as include from django.urls.resolvers import URLPattern, URLResolver @@ -12,13 +14,18 @@ handler500: Any def url( regex: str, view: Optional[ - Union[Callable, Tuple[None, None, None], Tuple[str, str, str]] + Union[ + Callable, + Tuple[List[Union[URLPattern, URLResolver]], str, str], + Tuple[Union[List[URLPattern], List[URLResolver]], None, None], + ] ], kwargs: Optional[ Union[ + Dict[str, Dict[str, Type[FlatPageSitemap]]], Dict[str, Dict[str, Sitemap]], - Dict[str, Union[Dict[str, Type[Sitemap]], str]], - Dict[str, Union[int, str]], + Dict[str, OrderedDict], + Dict[str, str], ] ] = ..., name: Optional[str] = ..., diff --git a/django-stubs/contrib/admin/filters.pyi b/django-stubs/contrib/admin/filters.pyi index 04a72de..1aad624 100644 --- a/django-stubs/contrib/admin/filters.pyi +++ b/django-stubs/contrib/admin/filters.pyi @@ -48,7 +48,7 @@ class FieldListFilter(ListFilter): title: Any = ... def __init__( self, - field: Union[Field, ForeignObjectRel], + field: Union[Field, reverse_related.ForeignObjectRel], request: WSGIRequest, params: Dict[str, str], model: Type[Model], @@ -63,21 +63,13 @@ class FieldListFilter(ListFilter): def register( cls, test: Callable, - list_filter_class: Type[ - Union[ - AllValuesFieldListFilter, - BooleanFieldListFilter, - ChoicesFieldListFilter, - DateFieldListFilter, - RelatedFieldListFilter, - ] - ], + list_filter_class: Type[FieldListFilter], take_priority: bool = ..., ) -> None: ... @classmethod def create( cls, - field: Union[Field, ForeignObjectRel], + field: Union[Field, reverse_related.ForeignObjectRel], request: WSGIRequest, params: Dict[str, str], model: Type[Model], @@ -115,7 +107,7 @@ class RelatedFieldListFilter(FieldListFilter): field: FieldCacheMixin, request: WSGIRequest, model_admin: ModelAdmin, - ) -> List[Tuple[str, str]]: ... + ) -> List[Tuple[Union[int, str], str]]: ... def choices(self, changelist: Any) -> None: ... class BooleanFieldListFilter(FieldListFilter): @@ -209,4 +201,4 @@ class RelatedOnlyFieldListFilter(RelatedFieldListFilter): used_parameters: Dict[Any, Any] def field_choices( self, field: RelatedField, request: WSGIRequest, model_admin: ModelAdmin - ) -> List[Tuple[str, str]]: ... + ) -> List[Tuple[Union[int, str], str]]: ... diff --git a/django-stubs/contrib/admin/helpers.pyi b/django-stubs/contrib/admin/helpers.pyi index ccf0920..5281375 100644 --- a/django-stubs/contrib/admin/helpers.pyi +++ b/django-stubs/contrib/admin/helpers.pyi @@ -135,12 +135,7 @@ class InlineAdminFormSet: def __iter__(self) -> Iterator[InlineAdminForm]: ... def fields( self - ) -> Iterator[ - Union[ - Dict[str, Union[Dict[str, bool], bool, str]], - Dict[str, Union[bool, Widget, str]], - ] - ]: ... + ) -> Iterator[Dict[str, Union[Dict[str, bool], bool, Widget, str]]]: ... def inline_formset_data(self) -> str: ... @property def forms(self): ... diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 9bff7e8..f1a299e 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -3,7 +3,7 @@ from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union from django.contrib.admin.filters import SimpleListFilter from django.contrib.admin.models import LogEntry -from django.contrib.admin.sites import AdminSite, DefaultAdminSite +from django.contrib.admin.sites import AdminSite from django.contrib.admin.views.main import ChangeList from django.contrib.auth.forms import AdminPasswordChangeForm from django.contrib.contenttypes.models import ContentType @@ -87,20 +87,9 @@ class BaseModelAdmin: def get_fieldsets( self, request: WSGIRequest, obj: Optional[Model] = ... ) -> Union[ - List[ - Tuple[ - None, - Union[ - Dict[str, List[Any]], - Dict[str, List[Union[Callable, str]]], - Dict[str, List[str]], - Dict[str, Tuple[str, str]], - ], - ] - ], - Tuple[Tuple[None, Dict[str, Tuple[Tuple[str, str]]]]], + List[Tuple[None, Dict[str, List[Union[Callable, str]]]]], Tuple[ - Tuple[str, Dict[str, Tuple[str]]], Tuple[str, Dict[str, Tuple[str]]] + Tuple[Optional[str], Dict[str, Tuple[Union[Tuple[str, str], str]]]] ], ]: ... def get_ordering(self, request: WSGIRequest) -> Union[List[str], Tuple]: ... @@ -130,7 +119,12 @@ class BaseModelAdmin: class ModelAdmin(BaseModelAdmin): formfield_overrides: Dict[ - Type[Any], + Type[ + Union[ + django.db.models.fields.DateTimeCheckMixin, + django.db.models.fields.Field, + ] + ], Dict[ str, Type[ @@ -173,9 +167,7 @@ class ModelAdmin(BaseModelAdmin): opts: django.db.models.options.Options = ... admin_site: django.contrib.admin.sites.AdminSite = ... def __init__( - self, - model: Type[Model], - admin_site: Optional[Union[AdminSite, DefaultAdminSite]], + self, model: Type[Model], admin_site: Optional[AdminSite] ) -> None: ... def get_inline_instances( self, request: WSGIRequest, obj: Optional[Model] = ... diff --git a/django-stubs/contrib/admin/templatetags/admin_list.pyi b/django-stubs/contrib/admin/templatetags/admin_list.pyi index 531b25d..13827e8 100644 --- a/django-stubs/contrib/admin/templatetags/admin_list.pyi +++ b/django-stubs/contrib/admin/templatetags/admin_list.pyi @@ -17,10 +17,7 @@ DOT: str def paginator_number(cl: ChangeList, i: int) -> SafeText: ... def pagination( cl: ChangeList -) -> Union[ - Dict[str, Union[List[Union[int, str]], ChangeList, int, str]], - Dict[str, Union[ChangeList, int, range, str]], -]: ... +) -> Dict[str, Union[List[Union[int, str]], ChangeList, int, range, str]]: ... def pagination_tag(parser: Parser, token: Token) -> InclusionAdminNode: ... def result_headers( cl: ChangeList diff --git a/django-stubs/contrib/admin/utils.pyi b/django-stubs/contrib/admin/utils.pyi index 2c3e991..4787481 100644 --- a/django-stubs/contrib/admin/utils.pyi +++ b/django-stubs/contrib/admin/utils.pyi @@ -1,19 +1,20 @@ -from datetime import date, datetime +from datetime import datetime from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union from uuid import UUID from django.contrib.admin.options import BaseModelAdmin from django.contrib.admin.sites import AdminSite from django.contrib.auth.forms import AdminPasswordChangeForm -from django.contrib.contenttypes.fields import GenericForeignKey from django.core.handlers.wsgi import WSGIRequest from django.db.models.base import Model from django.db.models.deletion import Collector from django.db.models.fields import Field from django.db.models.fields.mixins import FieldCacheMixin -from django.db.models.fields.reverse_related import ManyToOneRel, OneToOneRel +from django.db.models.fields.reverse_related import (ForeignObjectRel, + ManyToOneRel, OneToOneRel) from django.db.models.options import Options from django.db.models.query import QuerySet +from django.utils.safestring import SafeText class FieldIsAForeignKeyColumnName(Exception): ... @@ -34,30 +35,9 @@ def flatten( ) -> List[Union[Callable, str]]: ... def flatten_fieldsets( fieldsets: Union[ - List[ - Tuple[ - None, - Union[ - Dict[str, List[Any]], - Dict[str, List[Union[Callable, str]]], - Dict[str, List[str]], - Dict[str, Tuple[str, str]], - ], - ] - ], - List[Tuple[str, Dict[str, Tuple[str]]]], + List[Tuple[Optional[str], Dict[str, Tuple[str]]]], Tuple[ - Union[ - Tuple[Dict[str, Tuple[str]], Dict[str, Tuple[str]]], - Tuple[ - None, - Union[ - Dict[str, Tuple[Tuple[str, str]]], - Dict[str, Tuple[str, str, List[str]]], - Dict[str, Tuple[str, str, Tuple[str, str]]], - ], - ], - ] + Tuple[Optional[str], Dict[str, Tuple[Union[Tuple[str, str], str]]]] ], ] ) -> List[Union[Callable, str]]: ... @@ -88,10 +68,7 @@ class NestedObjects(Collector): ) -> QuerySet: ... def nested( self, format_callback: Callable = ... - ) -> Union[ - List[Union[List[Union[List[int], int]], int]], - List[Union[List[Union[List[str], str]], str]], - ]: ... + ) -> Union[List[SafeText], List[int]]: ... def can_fast_delete(self, *args: Any, **kwargs: Any) -> bool: ... def model_format_dict(obj: Any): ... @@ -100,27 +77,18 @@ def model_ngettext( ) -> str: ... def lookup_field( name: Union[Callable, str], obj: Model, model_admin: BaseModelAdmin = ... -) -> Union[ - Tuple[None, Callable, Optional[Callable]], - Tuple[None, Union[date, Model, int, str], Union[date, Model, int, str]], - Tuple[Field, None, Any], -]: ... +) -> Tuple[Optional[Field], Callable, Callable]: ... def label_for_field( name: Union[Callable, str], model: Type[Model], model_admin: Optional[BaseModelAdmin] = ..., return_attr: bool = ..., -) -> Union[ - Tuple[ - Optional[Union[Callable, GenericForeignKey]], - Optional[Union[Callable, GenericForeignKey]], - ], - Tuple[str, Type[str]], - str, -]: ... +) -> Union[Tuple[Optional[str], Union[Callable, Type[str]]], str]: ... def help_text_for_field(name: str, model: Type[Model]) -> str: ... def display_for_field( - value: Any, field: Union[Field, OneToOneRel], empty_value_display: str + value: Any, + field: Union[Field, reverse_related.OneToOneRel], + empty_value_display: str, ) -> str: ... def display_for_value( value: Any, empty_value_display: str, boolean: bool = ... @@ -129,14 +97,14 @@ def display_for_value( class NotRelationField(Exception): ... def get_model_from_relation( - field: Union[Field, mixins.FieldCacheMixin] + field: Union[Field, reverse_related.ForeignObjectRel] ) -> Type[Model]: ... def reverse_field_path( model: Type[Model], path: str ) -> Tuple[Type[Model], str]: ... def get_fields_from_path( model: Type[Model], path: str -) -> List[Union[Field, mixins.FieldCacheMixin]]: ... +) -> List[Union[Field, FieldCacheMixin]]: ... def construct_change_message( form: AdminPasswordChangeForm, formsets: None, add: bool ) -> List[Dict[str, Dict[str, List[str]]]]: ... diff --git a/django-stubs/contrib/admin/views/main.pyi b/django-stubs/contrib/admin/views/main.pyi index 1ce415d..c30759e 100644 --- a/django-stubs/contrib/admin/views/main.pyi +++ b/django-stubs/contrib/admin/views/main.pyi @@ -64,12 +64,10 @@ class ChangeList: def get_filters_params(self, params: None = ...) -> Dict[str, str]: ... def get_filters( self, request: WSGIRequest - ) -> Tuple[List[ListFilter], bool, bool, bool]: ... + ) -> Tuple[List[ListFilter], bool, Dict[str, Union[bool, str]], bool]: ... def get_query_string( self, - new_params: Optional[ - Union[Dict[str, None], Dict[str, Union[int, str]]] - ] = ..., + new_params: Optional[Dict[str, None]] = ..., remove: Optional[List[str]] = ..., ) -> str: ... result_count: Any = ... diff --git a/django-stubs/contrib/admin/widgets.pyi b/django-stubs/contrib/admin/widgets.pyi index e28f258..1c63ef1 100644 --- a/django-stubs/contrib/admin/widgets.pyi +++ b/django-stubs/contrib/admin/widgets.pyi @@ -1,10 +1,10 @@ from collections import OrderedDict from datetime import datetime -from typing import Any, Callable, Dict, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union from uuid import UUID from django import forms -from django.contrib.admin.sites import AdminSite, DefaultAdminSite +from django.contrib.admin.sites import AdminSite from django.db.models.fields.reverse_related import ForeignObjectRel from django.db.models.query_utils import Q from django.forms.fields import Field @@ -30,9 +30,9 @@ class FilteredSelectMultiple(forms.SelectMultiple): name: str, value: Union[List[Any], str], attrs: Optional[Dict[str, str]], - ) -> Union[ - Dict[ - str, + ) -> Dict[ + str, + Union[ Dict[ str, Union[ @@ -48,9 +48,6 @@ class FilteredSelectMultiple(forms.SelectMultiple): str, ], ], - ], - Dict[ - str, Dict[str, Union[Dict[str, Union[int, str]], List[str], bool, str]], ], ]: ... @@ -87,106 +84,30 @@ class AdminSplitDateTime(forms.SplitDateTimeWidget): name: str, value: Optional[Union[List[str], datetime]], attrs: Optional[Dict[str, Union[bool, str]]], - ) -> Union[ - Dict[ - str, - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ] - ], - ] - ], - bool, - str, - ] - ], - ], + ) -> Dict[ + str, + Union[ + Dict[ str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[str, str], - List[ - Dict[ - str, - Optional[Union[Dict[str, str], bool, str]], - ] - ], - bool, - str, - ] - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[Dict[str, Union[Dict[str, str], bool, str]]], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, + Optional[ Union[ Dict[str, Union[bool, str]], List[ Dict[ str, - Union[Dict[str, Union[bool, str]], bool, str], + Optional[ + Union[ + Dict[str, Union[bool, str]], bool, str + ] + ], ] ], bool, str, - ], + ] ], - str, ], - ], - Dict[ str, - Union[ - Dict[ - str, - Union[ - Dict[str, str], - List[Dict[str, Union[Dict[str, str], bool, str]]], - bool, - str, - ], - ], - str, - ], ], ]: ... @@ -203,7 +124,8 @@ def url_params_from_lookup_dict( Dict[str, Callable], Dict[str, List[str]], Dict[str, Tuple[str, str]], - Dict[str, Union[int, str]], + Dict[str, bool], + Dict[str, str], Q, ] ) -> Dict[str, str]: ... @@ -217,7 +139,7 @@ class ForeignKeyRawIdWidget(forms.TextInput): def __init__( self, rel: ForeignObjectRel, - admin_site: Union[AdminSite, DefaultAdminSite], + admin_site: AdminSite, attrs: None = ..., using: None = ..., ) -> None: ... @@ -226,18 +148,12 @@ class ForeignKeyRawIdWidget(forms.TextInput): name: str, value: Optional[Union[List[int], int, str, UUID]], attrs: Optional[Dict[str, Union[bool, str]]], - ) -> Union[ - Dict[ + ) -> Dict[ + str, + Union[ + Dict[str, Optional[Union[Dict[str, Union[bool, str]], bool, str]]], str, - Union[ - Dict[ - str, Optional[Union[Dict[str, Union[bool, str]], bool, str]] - ], - str, - ], ], - Dict[str, Union[Dict[str, Union[Dict[Any, Any], bool, str]], str]], - Dict[str, Union[Dict[str, Union[Dict[str, str], bool, str]], str]], ]: ... def base_url_parameters(self) -> Dict[str, str]: ... def url_parameters(self) -> Dict[str, str]: ... @@ -256,10 +172,7 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): name: str, value: Optional[List[int]], attrs: Optional[Dict[str, str]], - ) -> Union[ - Dict[str, Union[Dict[str, Union[Dict[Any, Any], bool, str]], str]], - Dict[str, Union[Dict[str, Union[Dict[str, str], bool, str]], str]], - ]: ... + ) -> Dict[str, Union[Dict[str, Union[Dict[str, str], bool, str]], str]]: ... def url_parameters(self) -> Dict[Any, Any]: ... def label_and_url_for_value(self, value: List[int]) -> Tuple[str, str]: ... def value_from_datadict( @@ -283,7 +196,7 @@ class RelatedFieldWidgetWrapper(forms.Widget): self, widget: ChoiceWidget, rel: ForeignObjectRel, - admin_site: Union[AdminSite, DefaultAdminSite], + admin_site: AdminSite, can_add_related: Optional[bool] = ..., can_change_related: bool = ..., can_delete_related: bool = ..., @@ -362,7 +275,7 @@ class AutocompleteMixin: def __init__( self, rel: ForeignObjectRel, - admin_site: Union[AdminSite, DefaultAdminSite], + admin_site: AdminSite, attrs: Optional[Dict[str, str]] = ..., choices: Tuple = ..., using: None = ..., @@ -378,7 +291,13 @@ class AutocompleteMixin: name: str, value: List[str], attr: Dict[str, Union[bool, str]] = ..., - ) -> List[Tuple[None, int, int]]: ... + ) -> List[ + Tuple[ + None, + List[Dict[str, Union[Dict[str, bool], Set[str], int, str]]], + int, + ] + ]: ... @property def media(self) -> Media: ... diff --git a/django-stubs/contrib/auth/admin.pyi b/django-stubs/contrib/auth/admin.pyi index 8ff5a63..1aa0b35 100644 --- a/django-stubs/contrib/auth/admin.pyi +++ b/django-stubs/contrib/auth/admin.pyi @@ -14,7 +14,12 @@ sensitive_post_parameters_m: Any class GroupAdmin(admin.ModelAdmin): admin_site: django.contrib.admin.sites.AdminSite formfield_overrides: Dict[ - Type[Any], + Type[ + Union[ + django.db.models.fields.DateTimeCheckMixin, + django.db.models.fields.Field, + ] + ], Dict[ str, Type[ @@ -40,7 +45,12 @@ class GroupAdmin(admin.ModelAdmin): class UserAdmin(admin.ModelAdmin): admin_site: django.contrib.admin.sites.AdminSite formfield_overrides: Dict[ - Type[Any], + Type[ + Union[ + django.db.models.fields.DateTimeCheckMixin, + django.db.models.fields.Field, + ] + ], Dict[ str, Type[ diff --git a/django-stubs/contrib/auth/context_processors.pyi b/django-stubs/contrib/auth/context_processors.pyi index caf9341..6f0f32b 100644 --- a/django-stubs/contrib/auth/context_processors.pyi +++ b/django-stubs/contrib/auth/context_processors.pyi @@ -22,7 +22,4 @@ class PermWrapper: def auth( request: HttpRequest -) -> Union[ - Dict[str, Union[PermWrapper, AnonymousUser]], - Dict[str, Union[PermWrapper, User]], -]: ... +) -> Dict[str, Union[PermWrapper, AnonymousUser, User]]: ... diff --git a/django-stubs/contrib/auth/forms.pyi b/django-stubs/contrib/auth/forms.pyi index 57871f0..ddcae50 100644 --- a/django-stubs/contrib/auth/forms.pyi +++ b/django-stubs/contrib/auth/forms.pyi @@ -14,20 +14,11 @@ class ReadOnlyPasswordHashWidget(forms.Widget): template_name: str = ... def get_context( self, name: str, value: Optional[str], attrs: Dict[str, str] - ) -> Union[ - Dict[ - str, - Union[ - Dict[str, Optional[Union[Dict[Any, Any], bool, str]]], - List[Dict[str, str]], - ], - ], - Dict[ - str, - Union[ - Dict[str, Optional[Union[Dict[str, str], bool, str]]], - List[Dict[str, str]], - ], + ) -> Dict[ + str, + Union[ + Dict[str, Optional[Union[Dict[str, str], bool, str]]], + List[Dict[str, str]], ], ]: ... diff --git a/django-stubs/contrib/auth/password_validation.pyi b/django-stubs/contrib/auth/password_validation.pyi index 30336c3..9e6221e 100644 --- a/django-stubs/contrib/auth/password_validation.pyi +++ b/django-stubs/contrib/auth/password_validation.pyi @@ -6,16 +6,12 @@ from django.contrib.auth.models import User def get_default_password_validators() -> Union[ - List[Union[CommonPasswordValidator, MinimumLengthValidator]], - List[Union[MinimumLengthValidator, UserAttributeSimilarityValidator]], - List[NumericPasswordValidator], + List[NumericPasswordValidator], List[UserAttributeSimilarityValidator] ]: ... def get_password_validators( validator_config: List[Dict[str, Union[Dict[str, int], str]]] ) -> Union[ - List[Union[CommonPasswordValidator, MinimumLengthValidator]], - List[Union[MinimumLengthValidator, UserAttributeSimilarityValidator]], - List[NumericPasswordValidator], + List[NumericPasswordValidator], List[UserAttributeSimilarityValidator] ]: ... def validate_password( password: str, diff --git a/django-stubs/contrib/auth/views.pyi b/django-stubs/contrib/auth/views.pyi index 05f674c..3e89b71 100644 --- a/django-stubs/contrib/auth/views.pyi +++ b/django-stubs/contrib/auth/views.pyi @@ -10,6 +10,7 @@ from django.core.handlers.wsgi import WSGIRequest from django.http.request import HttpRequest from django.http.response import HttpResponse, HttpResponseRedirect from django.template.response import TemplateResponse +from django.utils.datastructures import MultiValueDict from django.views.generic.base import TemplateView from django.views.generic.edit import FormView @@ -34,13 +35,14 @@ class LoginView(SuccessURLAllowedHostsMixin, FormView): def get_form_class(self) -> Type[AuthenticationForm]: ... def get_form_kwargs( self - ) -> Dict[str, Optional[Union[Dict[str, str], HttpRequest]]]: ... + ) -> Dict[ + str, Optional[Union[Dict[str, str], HttpRequest, MultiValueDict]] + ]: ... def form_valid(self, form: AuthenticationForm) -> HttpResponseRedirect: ... def get_context_data( self, **kwargs: Any - ) -> Union[ - Dict[str, Union[AuthenticationForm, LoginView, Site, str]], - Dict[str, Union[AuthenticationForm, LoginView, RequestSite, str]], + ) -> Dict[ + str, Union[AuthenticationForm, LoginView, Site, RequestSite, str] ]: ... class LogoutView(SuccessURLAllowedHostsMixin, TemplateView): @@ -105,7 +107,9 @@ class PasswordResetConfirmView(PasswordContextMixin, FormView): def get_user(self, uidb64: str) -> Optional[AbstractBaseUser]: ... def get_form_kwargs( self - ) -> Dict[str, Optional[Union[Dict[Any, Any], AbstractBaseUser]]]: ... + ) -> Dict[ + str, Optional[Union[Dict[Any, Any], AbstractBaseUser, MultiValueDict]] + ]: ... def form_valid(self, form: SetPasswordForm) -> HttpResponseRedirect: ... def get_context_data(self, **kwargs: Any): ... @@ -122,7 +126,7 @@ class PasswordChangeView(PasswordContextMixin, FormView): def dispatch(self, *args: Any, **kwargs: Any) -> HttpResponse: ... def get_form_kwargs( self - ) -> Dict[str, Optional[Union[Dict[Any, Any], User]]]: ... + ) -> Dict[str, Optional[Union[Dict[Any, Any], User, MultiValueDict]]]: ... def form_valid(self, form: PasswordChangeForm) -> HttpResponseRedirect: ... class PasswordChangeDoneView(PasswordContextMixin, TemplateView): diff --git a/django-stubs/contrib/contenttypes/fields.pyi b/django-stubs/contrib/contenttypes/fields.pyi index 04671cf..ea3d783 100644 --- a/django-stubs/contrib/contenttypes/fields.pyi +++ b/django-stubs/contrib/contenttypes/fields.pyi @@ -42,9 +42,7 @@ class GenericForeignKey(FieldCacheMixin): ) -> None: ... def get_filter_kwargs_for_object( self, obj: Model - ) -> Union[ - Dict[str, Optional[ContentType]], Dict[str, Union[ContentType, int]] - ]: ... + ) -> Dict[str, Optional[ContentType]]: ... def get_forward_related_filter(self, obj: Model) -> Dict[str, int]: ... def check(self, **kwargs: Any) -> List[Error]: ... def get_cache_name(self) -> str: ... diff --git a/django-stubs/contrib/messages/context_processors.pyi b/django-stubs/contrib/messages/context_processors.pyi index 36888dd..bca65f7 100644 --- a/django-stubs/contrib/messages/context_processors.pyi +++ b/django-stubs/contrib/messages/context_processors.pyi @@ -6,7 +6,4 @@ from django.http.request import HttpRequest def messages( request: HttpRequest -) -> Union[ - Dict[str, Union[Dict[str, int], List[Any]]], - Dict[str, Union[Dict[str, int], BaseStorage]], -]: ... +) -> Dict[str, Union[Dict[str, int], List[Any], BaseStorage]]: ... diff --git a/django-stubs/contrib/messages/storage/cookie.pyi b/django-stubs/contrib/messages/storage/cookie.pyi index af36dcd..fabbd24 100644 --- a/django-stubs/contrib/messages/storage/cookie.pyi +++ b/django-stubs/contrib/messages/storage/cookie.pyi @@ -32,25 +32,7 @@ class MessageDecoder(json.JSONDecoder): List[Union[int, str]], ], ], - List[ - Union[ - Dict[ - str, - Union[ - List[ - Union[ - Dict[str, List[Union[int, str]]], - List[Union[int, str]], - ] - ], - List[Union[int, str]], - ], - ], - List[Union[int, str]], - ] - ], List[Union[List[Union[int, str]], str]], - List[Union[int, str]], str, ], ) -> Union[ diff --git a/django-stubs/contrib/postgres/fields/array.pyi b/django-stubs/contrib/postgres/fields/array.pyi index 2dcd1e1..bf776a5 100644 --- a/django-stubs/contrib/postgres/fields/array.pyi +++ b/django-stubs/contrib/postgres/fields/array.pyi @@ -1,7 +1,6 @@ from typing import Any, Dict, List, Optional, Tuple, Union from django.contrib.postgres import lookups -from django.contrib.postgres.fields.mixins import CheckFieldDefaultMixin from django.db.models import Field, Transform from django.db.models.fields import Field from django.db.models.lookups import Exact, In @@ -17,10 +16,7 @@ class ArrayField(CheckFieldDefaultMixin, Field): default_validators: Any = ... from_db_value: Any = ... def __init__( - self, - base_field: Union[CheckFieldDefaultMixin, Field], - size: None = ..., - **kwargs: Any + self, base_field: Field, size: None = ..., **kwargs: Any ) -> None: ... @property def model(self): ... diff --git a/django-stubs/contrib/sessions/backends/base.pyi b/django-stubs/contrib/sessions/backends/base.pyi index 14b0cdc..7ab3047 100644 --- a/django-stubs/contrib/sessions/backends/base.pyi +++ b/django-stubs/contrib/sessions/backends/base.pyi @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta +from datetime import datetime from typing import Any, Dict, Optional, Union from django.db.models.base import Model @@ -29,21 +29,8 @@ class SessionBase: def set_test_cookie(self) -> None: ... def test_cookie_worked(self) -> bool: ... def delete_test_cookie(self) -> None: ... - def encode( - self, - session_dict: Union[ - Dict[str, Union[datetime, str]], - Dict[str, Union[int, str]], - Dict[str, Model], - ], - ) -> str: ... - def decode( - self, session_data: Union[bytes, str] - ) -> Union[ - Dict[str, Union[datetime, str]], - Dict[str, Union[int, str]], - Dict[str, Model], - ]: ... + def encode(self, session_dict: Dict[str, Model]) -> str: ... + def decode(self, session_data: Union[bytes, str]) -> Dict[str, Model]: ... def update(self, dict_: Dict[str, int]) -> None: ... def has_key(self, key: Any): ... def keys(self): ... @@ -54,9 +41,7 @@ class SessionBase: session_key: Any = ... def get_expiry_age(self, **kwargs: Any) -> int: ... def get_expiry_date(self, **kwargs: Any) -> datetime: ... - def set_expiry( - self, value: Optional[Union[datetime, timedelta, int]] - ) -> None: ... + def set_expiry(self, value: Optional[Union[datetime, int]]) -> None: ... def get_expire_at_browser_close(self) -> bool: ... def flush(self) -> None: ... def cycle_key(self) -> None: ... diff --git a/django-stubs/contrib/sessions/backends/db.pyi b/django-stubs/contrib/sessions/backends/db.pyi index 1e74cbd..8034e11 100644 --- a/django-stubs/contrib/sessions/backends/db.pyi +++ b/django-stubs/contrib/sessions/backends/db.pyi @@ -1,4 +1,3 @@ -from datetime import datetime from typing import Any, Dict, Optional, Type, Union from django.contrib.sessions.backends.base import SessionBase @@ -14,19 +13,12 @@ class SessionStore(SessionBase): @classmethod def get_model_class(cls) -> Type[Session]: ... def model(self) -> Type[AbstractBaseSession]: ... - def load( - self - ) -> Union[Dict[str, Model], Dict[str, int], Dict[str, str]]: ... + def load(self) -> Dict[str, Union[Model, int, str]]: ... def exists(self, session_key: Optional[str]) -> bool: ... modified: bool = ... def create(self) -> None: ... def create_model_instance( - self, - data: Union[ - Dict[str, Union[datetime, str]], - Dict[str, Union[int, str]], - Dict[str, Model], - ], + self, data: Dict[str, Model] ) -> AbstractBaseSession: ... def save(self, must_create: bool = ...) -> None: ... def delete(self, session_key: Optional[str] = ...) -> None: ... diff --git a/django-stubs/contrib/sessions/serializers.pyi b/django-stubs/contrib/sessions/serializers.pyi index 7ece666..1aced30 100644 --- a/django-stubs/contrib/sessions/serializers.pyi +++ b/django-stubs/contrib/sessions/serializers.pyi @@ -1,16 +1,11 @@ -from datetime import datetime -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Optional from django.core.signing import JSONSerializer as BaseJSONSerializer from django.db.models.base import Model class PickleSerializer: - def dumps( - self, obj: Union[Dict[str, Union[datetime, str]], Dict[str, Model]] - ) -> bytes: ... - def loads( - self, data: bytes - ) -> Union[Dict[str, Union[datetime, str]], Dict[str, Model]]: ... + def dumps(self, obj: Dict[str, Model]) -> bytes: ... + def loads(self, data: bytes) -> Dict[str, Model]: ... JSONSerializer = BaseJSONSerializer diff --git a/django-stubs/contrib/sitemaps/__init__.pyi b/django-stubs/contrib/sitemaps/__init__.pyi index 32a9c7a..82d70ea 100644 --- a/django-stubs/contrib/sitemaps/__init__.pyi +++ b/django-stubs/contrib/sitemaps/__init__.pyi @@ -35,10 +35,7 @@ class GenericSitemap(Sitemap): protocol: None = ... def __init__( self, - info_dict: Union[ - Dict[str, Union[datetime, QuerySet]], - Dict[str, Union[QuerySet, str]], - ], + info_dict: Dict[str, Union[datetime, QuerySet, str]], priority: Optional[float] = ..., changefreq: Optional[str] = ..., protocol: Optional[str] = ..., diff --git a/django-stubs/contrib/sitemaps/views.pyi b/django-stubs/contrib/sitemaps/views.pyi index cd1c264..8e5b74a 100644 --- a/django-stubs/contrib/sitemaps/views.pyi +++ b/django-stubs/contrib/sitemaps/views.pyi @@ -1,3 +1,4 @@ +from collections import OrderedDict from typing import Any, Callable, Dict, Optional, Type, Union from django.contrib.sitemaps import GenericSitemap, Sitemap @@ -8,14 +9,16 @@ from django.template.response import TemplateResponse def x_robots_tag(func: Callable) -> Callable: ... def index( request: WSGIRequest, - sitemaps: Union[Dict[str, Type[Sitemap]], Dict[str, Sitemap]], + sitemaps: Dict[str, Union[Type[Sitemap], Sitemap]], template_name: str = ..., content_type: str = ..., sitemap_url_name: str = ..., ) -> TemplateResponse: ... def sitemap( request: WSGIRequest, - sitemaps: Union[Dict[str, Type[Sitemap]], Dict[str, GenericSitemap]], + sitemaps: Union[ + Dict[str, Type[Sitemap]], Dict[str, GenericSitemap], OrderedDict + ], section: Optional[str] = ..., template_name: str = ..., content_type: str = ..., diff --git a/django-stubs/contrib/staticfiles/management/commands/collectstatic.pyi b/django-stubs/contrib/staticfiles/management/commands/collectstatic.pyi index f769906..4c46b52 100644 --- a/django-stubs/contrib/staticfiles/management/commands/collectstatic.pyi +++ b/django-stubs/contrib/staticfiles/management/commands/collectstatic.pyi @@ -1,6 +1,6 @@ -from typing import Any, Dict, List, Optional, Union +from typing import Any, Dict, List, Optional -from django.core.files.storage import DefaultStorage, FileSystemStorage +from django.core.files.storage import FileSystemStorage from django.core.management.base import BaseCommand, CommandParser @@ -32,20 +32,11 @@ class Command(BaseCommand): def is_local_storage(self) -> bool: ... def clear_dir(self, path: str) -> None: ... def delete_file( - self, - path: str, - prefixed_path: str, - source_storage: Union[DefaultStorage, FileSystemStorage], + self, path: str, prefixed_path: str, source_storage: FileSystemStorage ) -> bool: ... def link_file( - self, - path: str, - prefixed_path: str, - source_storage: Union[DefaultStorage, FileSystemStorage], + self, path: str, prefixed_path: str, source_storage: FileSystemStorage ) -> None: ... def copy_file( - self, - path: str, - prefixed_path: str, - source_storage: Union[DefaultStorage, FileSystemStorage], + self, path: str, prefixed_path: str, source_storage: FileSystemStorage ) -> None: ... diff --git a/django-stubs/contrib/staticfiles/utils.pyi b/django-stubs/contrib/staticfiles/utils.pyi index 5eaebf2..33c343e 100644 --- a/django-stubs/contrib/staticfiles/utils.pyi +++ b/django-stubs/contrib/staticfiles/utils.pyi @@ -1,14 +1,14 @@ from collections import OrderedDict from typing import Any, Iterator, List, Optional, Tuple, Union -from django.core.files.storage import DefaultStorage, FileSystemStorage +from django.core.files.storage import FileSystemStorage def matches_patterns( path: str, patterns: Union[List[str], Tuple[str], OrderedDict] = ... ) -> bool: ... def get_files( - storage: Union[DefaultStorage, FileSystemStorage], + storage: FileSystemStorage, ignore_patterns: List[str] = ..., location: str = ..., ) -> Iterator[str]: ... diff --git a/django-stubs/core/cache/__init__.pyi b/django-stubs/core/cache/__init__.pyi index cc69cd0..e5befdb 100644 --- a/django-stubs/core/cache/__init__.pyi +++ b/django-stubs/core/cache/__init__.pyi @@ -1,3 +1,4 @@ +from collections import OrderedDict from typing import Any, Callable, Dict, Optional, Union from django.core.cache.backends.base import BaseCache as BaseCache @@ -15,7 +16,7 @@ class CacheHandler: class DefaultCacheProxy: def __getattr__( self, name: str - ) -> Union[Callable, Dict[str, float], int]: ... + ) -> Union[Callable, Dict[str, float], OrderedDict, int]: ... def __setattr__(self, name: str, value: Callable) -> None: ... def __delattr__(self, name: Any): ... def __contains__(self, key: str) -> bool: ... diff --git a/django-stubs/core/cache/backends/base.pyi b/django-stubs/core/cache/backends/base.pyi index c898c12..8aad98e 100644 --- a/django-stubs/core/cache/backends/base.pyi +++ b/django-stubs/core/cache/backends/base.pyi @@ -1,3 +1,4 @@ +from collections import OrderedDict from typing import Any, Callable, Dict, List, Optional, Union from django.core.exceptions import ImproperlyConfigured @@ -21,13 +22,7 @@ class BaseCache: key_func: Callable = ... def __init__( self, - params: Union[ - Dict[str, Callable], - Dict[str, Dict[str, int]], - Dict[str, None], - Dict[str, int], - Dict[str, str], - ], + params: Dict[str, Optional[Union[Callable, Dict[str, int], int, str]]], ) -> None: ... def get_backend_timeout(self, timeout: Any = ...) -> Optional[float]: ... def make_key( @@ -59,7 +54,7 @@ class BaseCache: def delete(self, key: Any, version: Optional[Any] = ...) -> None: ... def get_many( self, keys: List[str], version: Optional[int] = ... - ) -> Union[Dict[str, int], Dict[str, str]]: ... + ) -> Dict[str, Union[int, str]]: ... def get_or_set( self, key: str, @@ -78,9 +73,7 @@ class BaseCache: def set_many( self, data: Union[ - Dict[str, Union[Dict[str, int], str]], - Dict[str, bytes], - Dict[str, int], + Dict[str, bytes], Dict[str, int], Dict[str, str], OrderedDict ], timeout: Any = ..., version: Optional[Union[int, str]] = ..., diff --git a/django-stubs/core/cache/backends/db.pyi b/django-stubs/core/cache/backends/db.pyi index 5ce3c44..c21caca 100644 --- a/django-stubs/core/cache/backends/db.pyi +++ b/django-stubs/core/cache/backends/db.pyi @@ -25,12 +25,7 @@ class BaseDatabaseCache(BaseCache): def __init__( self, table: str, - params: Union[ - Dict[str, Callable], - Dict[str, Dict[str, int]], - Dict[str, int], - Dict[str, str], - ], + params: Dict[str, Union[Callable, Dict[str, int], int, str]], ) -> None: ... class DatabaseCache(BaseDatabaseCache): diff --git a/django-stubs/core/cache/backends/filebased.pyi b/django-stubs/core/cache/backends/filebased.pyi index 4f1b75b..fb64597 100644 --- a/django-stubs/core/cache/backends/filebased.pyi +++ b/django-stubs/core/cache/backends/filebased.pyi @@ -12,12 +12,7 @@ class FileBasedCache(BaseCache): def __init__( self, dir: str, - params: Union[ - Dict[str, Callable], - Dict[str, Dict[str, int]], - Dict[str, int], - Dict[str, str], - ], + params: Dict[str, Union[Callable, Dict[str, int], int, str]], ) -> None: ... def add( self, diff --git a/django-stubs/core/cache/backends/locmem.pyi b/django-stubs/core/cache/backends/locmem.pyi index eac89c3..0f13e96 100644 --- a/django-stubs/core/cache/backends/locmem.pyi +++ b/django-stubs/core/cache/backends/locmem.pyi @@ -1,4 +1,3 @@ -from datetime import datetime from typing import Any, Callable, Dict, Optional, Union from django.core.cache.backends.base import BaseCache @@ -12,20 +11,12 @@ class LocMemCache(BaseCache): def __init__( self, name: str, - params: Union[ - Dict[str, Callable], - Dict[str, Dict[str, int]], - Dict[str, None], - Dict[str, int], - Dict[str, str], - ], + params: Dict[str, Optional[Union[Callable, Dict[str, int], int, str]]], ) -> None: ... def add( self, key: str, - value: Union[ - Dict[str, Union[datetime, str]], Dict[str, int], bytes, int, str - ], + value: Union[Dict[str, int], Dict[str, str], bytes, int, str], timeout: Any = ..., version: Optional[int] = ..., ) -> Any: ... diff --git a/django-stubs/core/exceptions.pyi b/django-stubs/core/exceptions.pyi index 9749240..a12ff57 100644 --- a/django-stubs/core/exceptions.pyi +++ b/django-stubs/core/exceptions.pyi @@ -1,6 +1,7 @@ from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, Union from django.db.models.base import Model +from django.forms.utils import ErrorDict, ErrorList class FieldDoesNotExist(Exception): ... @@ -35,9 +36,10 @@ class ValidationError(Exception): self, message: Union[ Dict[str, List[ValidationError]], - Dict[str, Union[List[str], str]], + Dict[str, ErrorList], List[Union[ValidationError, str]], ValidationError, + ErrorList, str, ], code: Optional[str] = ..., @@ -53,8 +55,8 @@ class ValidationError(Exception): @property def messages(self) -> List[str]: ... def update_error_dict( - self, error_dict: Dict[str, List[ValidationError]] - ) -> Dict[str, List[ValidationError]]: ... + self, error_dict: Union[Dict[str, List[ValidationError]], ErrorDict] + ) -> Union[Dict[str, List[ValidationError]], ErrorDict]: ... def __iter__(self) -> Iterator[Union[Tuple[str, List[str]], str]]: ... class EmptyResultSet(Exception): ... diff --git a/django-stubs/core/management/commands/inspectdb.pyi b/django-stubs/core/management/commands/inspectdb.pyi index 191a5b6..82eaade 100644 --- a/django-stubs/core/management/commands/inspectdb.pyi +++ b/django-stubs/core/management/commands/inspectdb.pyi @@ -26,13 +26,7 @@ class Command(BaseCommand): def get_meta( self, table_name: str, - constraints: Dict[ - str, - Union[ - Dict[str, Union[List[str], Tuple[str, str], bool]], - Dict[str, Union[List[str], bool, str]], - ], - ], + constraints: Dict[str, Dict[str, Union[List[str], bool]]], column_to_field_name: Dict[str, str], is_view: bool, ) -> List[str]: ... diff --git a/django-stubs/core/management/commands/loaddata.pyi b/django-stubs/core/management/commands/loaddata.pyi index e0b5c1e..43c3fee 100644 --- a/django-stubs/core/management/commands/loaddata.pyi +++ b/django-stubs/core/management/commands/loaddata.pyi @@ -29,7 +29,7 @@ class Command(BaseCommand): def load_label(self, fixture_label: str) -> None: ... def find_fixtures( self, fixture_label: str - ) -> List[Tuple[str, str, str]]: ... + ) -> List[Tuple[str, Optional[str], str]]: ... def fixture_dirs(self) -> List[str]: ... def parse_name( self, fixture_name: str diff --git a/django-stubs/core/serializers/__init__.pyi b/django-stubs/core/serializers/__init__.pyi index d24d7d8..e4b4f23 100644 --- a/django-stubs/core/serializers/__init__.pyi +++ b/django-stubs/core/serializers/__init__.pyi @@ -3,8 +3,8 @@ from typing import (Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, Union) from django.apps.config import AppConfig -from django.core.serializers.python import Serializer -from django.core.serializers.xml_serializer import Deserializer, Serializer +from django.core.serializers.base import Serializer +from django.core.serializers.xml_serializer import Deserializer from django.db.models.base import Model from django.db.models.query import QuerySet @@ -22,11 +22,7 @@ def register_serializer( serializers: Optional[Dict[str, Any]] = ..., ) -> None: ... def unregister_serializer(format: str) -> None: ... -def get_serializer( - format: str -) -> Union[ - Type[Union[python.Serializer, xml_serializer.Serializer]], BadSerializer -]: ... +def get_serializer(format: str) -> Union[Type[Serializer], BadSerializer]: ... def get_serializer_formats() -> List[str]: ... def get_public_serializer_formats() -> List[str]: ... def get_deserializer(format: str) -> Union[Callable, Type[Deserializer]]: ... diff --git a/django-stubs/core/serializers/base.pyi b/django-stubs/core/serializers/base.pyi index 1db4e0e..f4c43b7 100644 --- a/django-stubs/core/serializers/base.pyi +++ b/django-stubs/core/serializers/base.pyi @@ -1,6 +1,5 @@ from collections import OrderedDict -from datetime import date, datetime, time, timedelta -from decimal import Decimal +from datetime import date from io import BufferedReader, StringIO, TextIOWrapper from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, Union from uuid import UUID @@ -96,23 +95,12 @@ class DeserializedObject: def build_instance( Model: Type[Model], - data: Union[ - Dict[str, Optional[Union[int, str]]], - Dict[str, Optional[datetime]], - Dict[str, Optional[timedelta]], - Dict[str, Optional[UUID]], - Dict[str, Union[date, int, str]], - Dict[str, Union[time, int]], - Dict[str, Union[Decimal, int, str]], - Dict[str, Union[float, str]], - Dict[str, Union[int, memoryview]], - Dict[str, Union[int, UUID]], - ], + data: Dict[str, Optional[Union[date, int, str, UUID]]], db: str, ) -> Model: ... def deserialize_m2m_values( field: ManyToManyField, - field_value: Union[List[List[str]], List[Union[int, str]]], + field_value: Union[List[List[str]], List[int]], using: str, ) -> List[int]: ... def deserialize_fk_value( diff --git a/django-stubs/core/serializers/json.pyi b/django-stubs/core/serializers/json.pyi index ee8bb89..ec87615 100644 --- a/django-stubs/core/serializers/json.pyi +++ b/django-stubs/core/serializers/json.pyi @@ -1,5 +1,5 @@ import json -from datetime import date, time, timedelta +from datetime import datetime from decimal import Decimal from typing import Any, Optional, Union from uuid import UUID @@ -32,6 +32,4 @@ class DjangoJSONEncoder(json.JSONEncoder): indent: None skipkeys: bool sort_keys: bool - def default( - self, o: Union[date, time, timedelta, Decimal, UUID] - ) -> str: ... + def default(self, o: Union[datetime, Decimal, UUID]) -> str: ... diff --git a/django-stubs/core/serializers/python.pyi b/django-stubs/core/serializers/python.pyi index c425810..f2daf1f 100644 --- a/django-stubs/core/serializers/python.pyi +++ b/django-stubs/core/serializers/python.pyi @@ -1,5 +1,4 @@ from collections import OrderedDict -from datetime import date from typing import Any, Dict, Iterator, List, Optional, Union from django.core.serializers import base @@ -29,77 +28,9 @@ class Serializer(base.Serializer): def Deserializer( object_list: Union[ - List[Dict[str, Optional[Union[Dict[str, None], str]]]], - List[Dict[str, Optional[Union[Dict[str, Union[float, str]], str]]]], - List[ - Dict[ - str, - Union[Dict[str, Union[List[List[str]], int, str]], int, str], - ] - ], - List[ - Dict[ - str, - Union[ - Dict[str, Union[List[Union[int, str]], int, str]], int, str - ], - ] - ], - List[ - Dict[ - str, - Union[Dict[str, Union[List[int], date, int, str]], int, str], - ] - ], - List[ - Union[ - Dict[str, Optional[Union[Dict[str, Optional[str]], str]]], - Dict[ - str, - Union[ - Dict[str, Union[List[List[str]], List[str], str]], - int, - str, - ], - ], - ] - ], - List[ - Union[ - Dict[str, Union[Dict[Any, Any], date, str]], - Dict[str, Union[Dict[Any, Any], float, str]], - Dict[str, Union[Dict[str, List[int]], int, str]], - Dict[str, Union[Dict[str, None], int, str]], - Dict[str, Union[Dict[str, Union[int, str]], int, str]], - Dict[str, Union[Dict[str, date], int, str]], - Dict[str, Union[Dict[str, float], int, str]], - ] - ], - List[ - Union[ - Dict[str, Union[Dict[str, List[str]], int, str]], - Dict[str, Union[Dict[str, Optional[str]], int, str]], - ] - ], - List[ - Union[ - Dict[str, Union[Dict[str, Union[List[Any], str]], int, str]], - Dict[ - str, - Union[ - Dict[str, Union[List[List[str]], bool, str]], int, str - ], - ], - ] - ], - List[ - Union[ - Dict[str, Union[Dict[str, Union[List[Any], str]], int, str]], - Dict[ - str, Union[Dict[str, Union[List[int], bool, str]], int, str] - ], - ] - ], + List[Dict[str, Optional[Union[Dict[str, Optional[str]], str]]]], + List[Dict[str, Union[Dict[str, Union[List[int], int, str]], int, str]]], + List[OrderedDict], ], *, using: Any = ..., diff --git a/django-stubs/db/backends/base/base.pyi b/django-stubs/db/backends/base/base.pyi index 88f82b0..bed148a 100644 --- a/django-stubs/db/backends/base/base.pyi +++ b/django-stubs/db/backends/base/base.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Dict, Iterator, List, Optional, Union +from typing import Any, Callable, Dict, Iterator, List, Optional from django.db.backends.sqlite3.base import (DatabaseWrapper, SQLiteCursorWrapper) @@ -48,9 +48,7 @@ class BaseDatabaseWrapper: validation: Any = ... def __init__( self, - settings_dict: Dict[ - str, Optional[Union[Dict[str, Optional[str]], int, str]] - ], + settings_dict: Dict[str, Dict[str, str]], alias: str = ..., allow_thread_sharing: bool = ..., ) -> None: ... diff --git a/django-stubs/db/backends/base/operations.pyi b/django-stubs/db/backends/base/operations.pyi index b2bd122..ba2858a 100644 --- a/django-stubs/db/backends/base/operations.pyi +++ b/django-stubs/db/backends/base/operations.pyi @@ -1,4 +1,4 @@ -from datetime import date, datetime, time, timedelta +from datetime import date, datetime, timedelta from decimal import Decimal from typing import Any, List, Optional, Set, Tuple, Type, Union @@ -27,10 +27,7 @@ class BaseDatabaseOperations: explain_prefix: Any = ... connection: django.db.DefaultConnectionProxy = ... def __init__( - self, - connection: Union[ - DefaultConnectionProxy, backends.base.base.BaseDatabaseWrapper - ], + self, connection: Union[DefaultConnectionProxy, BaseDatabaseWrapper] ) -> None: ... def autoinc_sql(self, table: str, column: str) -> None: ... def bulk_batch_size(self, fields: Any, objs: Any): ... @@ -111,12 +108,12 @@ class BaseDatabaseOperations: prep_for_iexact_query: Any = ... def validate_autopk_value(self, value: int) -> int: ... def adapt_unknown_value( - self, value: Union[date, time, Decimal, int, str] + self, value: Union[datetime, Decimal, int, str] ) -> Union[int, str]: ... def adapt_datefield_value(self, value: Optional[date]) -> Optional[str]: ... def adapt_datetimefield_value(self, value: None) -> None: ... def adapt_timefield_value( - self, value: Optional[Union[datetime, time]] + self, value: Optional[datetime] ) -> Optional[str]: ... def adapt_decimalfield_value( self, @@ -145,18 +142,12 @@ class BaseDatabaseOperations: def combine_duration_expression( self, connector: Any, sub_expressions: Any ): ... - def binary_placeholder_sql( - self, value: Optional[Union[Case, memoryview]] - ) -> str: ... + def binary_placeholder_sql(self, value: Optional[Case]) -> str: ... def modify_insert_params( self, placeholder: str, - params: Union[ - List[None], List[float], List[int], List[memoryview], List[str] - ], - ) -> Union[ - List[None], List[float], List[int], List[memoryview], List[str] - ]: ... + params: Union[List[None], List[bool], List[float], List[str]], + ) -> Union[List[None], List[bool], List[float], List[str]]: ... def integer_field_range(self, internal_type: Any): ... def subtract_temporals(self, internal_type: Any, lhs: Any, rhs: Any): ... def window_frame_start(self, start: Any): ... diff --git a/django-stubs/db/backends/base/schema.pyi b/django-stubs/db/backends/base/schema.pyi index 307e7b8..15582e3 100644 --- a/django-stubs/db/backends/base/schema.pyi +++ b/django-stubs/db/backends/base/schema.pyi @@ -63,9 +63,7 @@ class BaseDatabaseSchemaEditor: ) -> Union[Tuple[None, None], Tuple[str, List[Any]]]: ... def skip_default(self, field: Any): ... def prepare_default(self, value: Any) -> None: ... - def effective_default( - self, field: Field - ) -> Optional[Union[int, memoryview, str]]: ... + def effective_default(self, field: Field) -> Optional[Union[int, str]]: ... def quote_value(self, value: Any) -> None: ... def create_model(self, model: Type[Model]) -> None: ... def delete_model(self, model: Type[Model]) -> None: ... diff --git a/django-stubs/db/backends/mysql/client.pyi b/django-stubs/db/backends/mysql/client.pyi index 09d5111..2e9504b 100644 --- a/django-stubs/db/backends/mysql/client.pyi +++ b/django-stubs/db/backends/mysql/client.pyi @@ -8,10 +8,11 @@ class DatabaseClient(BaseDatabaseClient): @classmethod def settings_to_cmd_args( cls, - settings_dict: Union[ - Dict[str, Optional[Union[Dict[Any, Any], str]]], - Dict[str, Union[Dict[str, Dict[str, str]], int, str]], - Dict[str, Union[Dict[str, Union[int, str]], int, str]], + settings_dict: Dict[ + str, + Optional[ + Union[Dict[Any, Any], Dict[str, Dict[str, str]], int, str] + ], ], ) -> List[str]: ... def runshell(self) -> None: ... diff --git a/django-stubs/db/backends/sqlite3/base.pyi b/django-stubs/db/backends/sqlite3/base.pyi index 547ae77..3523af1 100644 --- a/django-stubs/db/backends/sqlite3/base.pyi +++ b/django-stubs/db/backends/sqlite3/base.pyi @@ -76,12 +76,7 @@ class SQLiteCursorWrapper(Database.Cursor): self, query: str, params: Optional[ - Union[ - List[Optional[Union[float, str]]], - List[Optional[Union[int, memoryview, str]]], - List[datetime], - Tuple, - ] + Union[List[bool], List[datetime], List[float], Tuple] ] = ..., ) -> SQLiteCursorWrapper: ... def executemany( diff --git a/django-stubs/db/backends/sqlite3/introspection.pyi b/django-stubs/db/backends/sqlite3/introspection.pyi index 2eba5c8..8536dcb 100644 --- a/django-stubs/db/backends/sqlite3/introspection.pyi +++ b/django-stubs/db/backends/sqlite3/introspection.pyi @@ -39,10 +39,4 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): ) -> Optional[str]: ... def get_constraints( self, cursor: CursorWrapper, table_name: str - ) -> Dict[ - str, - Union[ - Dict[str, Union[List[str], Tuple[str, str], bool]], - Dict[str, Union[List[str], bool, str]], - ], - ]: ... + ) -> Dict[str, Dict[str, Union[List[str], bool]]]: ... diff --git a/django-stubs/db/backends/sqlite3/operations.pyi b/django-stubs/db/backends/sqlite3/operations.pyi index 01a9b31..f94b547 100644 --- a/django-stubs/db/backends/sqlite3/operations.pyi +++ b/django-stubs/db/backends/sqlite3/operations.pyi @@ -24,7 +24,9 @@ class DatabaseOperations(BaseDatabaseOperations): fields: Union[List[Field], List[str], ImmutableList], objs: Union[List[Model], range], ) -> int: ... - def check_expression_support(self, expression: BaseExpression) -> None: ... + def check_expression_support( + self, expression: Union[BaseExpression, SQLiteNumericMixin] + ) -> None: ... def date_extract_sql(self, lookup_type: str, field_name: str) -> str: ... def date_interval_sql(self, timedelta: timedelta) -> str: ... def format_for_duration_arithmetic(self, sql: str) -> str: ... @@ -86,7 +88,7 @@ class DatabaseOperations(BaseDatabaseOperations): connection: DatabaseWrapper, ) -> Optional[time]: ... def get_decimalfield_converter( - self, expression: Union[Col, SQLiteNumericMixin] + self, expression: Expression ) -> Callable: ... def convert_uuidfield_value( self, value: Optional[str], expression: Col, connection: DatabaseWrapper diff --git a/django-stubs/db/backends/sqlite3/schema.pyi b/django-stubs/db/backends/sqlite3/schema.pyi index a2bf433..f335285 100644 --- a/django-stubs/db/backends/sqlite3/schema.pyi +++ b/django-stubs/db/backends/sqlite3/schema.pyi @@ -18,9 +18,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): def __exit__( self, exc_type: None, exc_value: None, traceback: None ) -> None: ... - def quote_value( - self, value: Optional[Union[int, memoryview, str]] - ) -> str: ... + def quote_value(self, value: Optional[Union[int, str]]) -> str: ... def alter_db_table( self, model: Type[Model], diff --git a/django-stubs/db/backends/utils.pyi b/django-stubs/db/backends/utils.pyi index 6fe9d51..a60882e 100644 --- a/django-stubs/db/backends/utils.pyi +++ b/django-stubs/db/backends/utils.pyi @@ -32,12 +32,7 @@ class CursorWrapper: self, sql: str, params: Optional[ - Union[ - List[Optional[Union[float, str]]], - List[Optional[Union[int, memoryview, str]]], - List[datetime], - Tuple, - ] + Union[List[bool], List[datetime], List[float], Tuple] ] = ..., ) -> Optional[SQLiteCursorWrapper]: ... def executemany( diff --git a/django-stubs/db/migrations/autodetector.pyi b/django-stubs/db/migrations/autodetector.pyi index 9a369d6..4a0d28c 100644 --- a/django-stubs/db/migrations/autodetector.pyi +++ b/django-stubs/db/migrations/autodetector.pyi @@ -31,31 +31,18 @@ class MigrationAutodetector: def deep_deconstruct(self, obj: Any) -> Any: ... def only_relation_agnostic_fields( self, fields: List[Tuple[str, Field]] - ) -> List[ - Tuple[ - str, - List[Any], - Union[ - Dict[str, Callable], - Dict[str, Union[Callable, bool]], - Dict[str, Union[bool, str]], - Dict[str, Union[int, str]], - Dict[str, bool], - Dict[str, int], - ], - ] - ]: ... + ) -> List[Tuple[str, List[Any], Dict[str, Union[Callable, int, str]]]]: ... def check_dependency( self, operation: Operation, - dependency: Tuple[str, str, Union[bool, str], Union[bool, str]], + dependency: Tuple[str, str, Optional[str], Union[bool, str]], ) -> bool: ... def add_operation( self, app_label: str, operation: Operation, dependencies: Optional[ - List[Tuple[str, str, Union[bool, str], Union[bool, str]]] + List[Tuple[str, str, Optional[str], Union[bool, str]]] ] = ..., beginning: bool = ..., ) -> None: ... diff --git a/django-stubs/db/migrations/executor.pyi b/django-stubs/db/migrations/executor.pyi index 70b100c..d59d515 100644 --- a/django-stubs/db/migrations/executor.pyi +++ b/django-stubs/db/migrations/executor.pyi @@ -19,9 +19,7 @@ class MigrationExecutor: def __init__( self, connection: Optional[ - Union[ - DefaultConnectionProxy, backends.base.base.BaseDatabaseWrapper - ] + Union[DefaultConnectionProxy, BaseDatabaseWrapper] ], progress_callback: Optional[Callable] = ..., ) -> None: ... @@ -29,7 +27,7 @@ class MigrationExecutor: self, targets: Union[List[Tuple[str, Optional[str]]], Set[Tuple[str, str]]], clean_start: bool = ..., - ) -> List[Tuple[bool, bool]]: ... + ) -> List[Tuple[Migration, bool]]: ... def migrate( self, targets: Optional[List[Tuple[str, Optional[str]]]], diff --git a/django-stubs/db/migrations/loader.pyi b/django-stubs/db/migrations/loader.pyi index 8eb6969..994b7f5 100644 --- a/django-stubs/db/migrations/loader.pyi +++ b/django-stubs/db/migrations/loader.pyi @@ -21,15 +21,15 @@ class MigrationLoader: def __init__( self, connection: Optional[ - Union[ - DefaultConnectionProxy, backends.base.base.BaseDatabaseWrapper - ] + Union[DefaultConnectionProxy, BaseDatabaseWrapper] ], load: bool = ..., ignore_no_migrations: bool = ..., ) -> None: ... @classmethod - def migrations_module(cls, app_label: str) -> Tuple[bool, bool]: ... + def migrations_module( + cls, app_label: str + ) -> Tuple[Optional[str], bool]: ... unmigrated_apps: Set[str] = ... migrated_apps: Set[str] = ... def load_disk(self) -> None: ... diff --git a/django-stubs/db/migrations/operations/base.pyi b/django-stubs/db/migrations/operations/base.pyi index d168951..3ac86d0 100644 --- a/django-stubs/db/migrations/operations/base.pyi +++ b/django-stubs/db/migrations/operations/base.pyi @@ -7,7 +7,9 @@ class Operation: atomic: bool = ... elidable: bool = ... serialization_expand_args: Any = ... - def __new__(cls: Type[Any], *args: Any, **kwargs: Any) -> Operation: ... + def __new__( + cls: Type[Operation], *args: Any, **kwargs: Any + ) -> Operation: ... def deconstruct(self): ... def state_forwards(self, app_label: Any, state: Any) -> None: ... def database_forwards( diff --git a/django-stubs/db/migrations/operations/models.pyi b/django-stubs/db/migrations/operations/models.pyi index 372a76c..8e6b372 100644 --- a/django-stubs/db/migrations/operations/models.pyi +++ b/django-stubs/db/migrations/operations/models.pyi @@ -1,10 +1,10 @@ from typing import Any, Dict, List, Optional, Set, Tuple, Type, Union +from django.contrib.auth.base_user import AbstractBaseUser from django.contrib.postgres.fields.citext import CIText from django.db.backends.sqlite3.schema import DatabaseSchemaEditor from django.db.migrations.operations.base import Operation from django.db.migrations.state import ProjectState -from django.db.models.base import Model from django.db.models.fields import Field from django.db.models.indexes import Index from django.db.models.manager import Manager @@ -39,12 +39,11 @@ class CreateModel(ModelOperation): fields: List[Tuple[str, Union[CIText, Field]]], options: Optional[ Union[ - Dict[str, Union[List[Any], bool]], Dict[str, Union[Set[Tuple[str, str]], Tuple[str], str]], Dict[str, Union[bool, str]], ] ] = ..., - bases: Optional[Tuple[Union[Type[Model], str]]] = ..., + bases: Optional[Tuple[Type[AbstractBaseUser]]] = ..., managers: Optional[List[Tuple[str, Manager]]] = ..., ) -> None: ... def deconstruct( diff --git a/django-stubs/db/migrations/recorder.pyi b/django-stubs/db/migrations/recorder.pyi index b1c1f12..8c5cdcc 100644 --- a/django-stubs/db/migrations/recorder.pyi +++ b/django-stubs/db/migrations/recorder.pyi @@ -20,9 +20,7 @@ class MigrationRecorder: def __init__( self, connection: Optional[ - Union[ - DefaultConnectionProxy, backends.base.base.BaseDatabaseWrapper - ] + Union[DefaultConnectionProxy, BaseDatabaseWrapper] ], ) -> None: ... @property diff --git a/django-stubs/db/migrations/state.pyi b/django-stubs/db/migrations/state.pyi index 0eef7a3..b192f09 100644 --- a/django-stubs/db/migrations/state.pyi +++ b/django-stubs/db/migrations/state.pyi @@ -27,24 +27,15 @@ class ModelState: fields: List[Tuple[str, Union[CIText, Field]]], options: Optional[ Union[ - Dict[str, Optional[List[Index]]], - Dict[ - str, - Union[ - List[Tuple[str, str]], - Set[Tuple[str, str]], - Tuple[str], - str, - ], - ], - Dict[str, Union[List[Index], bool]], - Dict[str, Union[List[str], Set[Tuple[str, str]]]], - Dict[str, Union[List[str], Tuple, bool]], - Dict[str, Union[List[str], bool, str]], - Dict[str, Union[Set[Tuple[str, str]], bool]], + Dict[str, List[Index]], + Dict[str, List[str]], + Dict[str, Set[Tuple[str, str]]], + Dict[str, Tuple[str]], + Dict[str, bool], + Dict[str, str], ] ] = ..., - bases: Optional[Tuple[Union[Type[Model], str]]] = ..., + bases: Optional[Tuple[Type[Model]]] = ..., managers: Optional[List[Tuple[str, Manager]]] = ..., ) -> None: ... def clone(self) -> ModelState: ... diff --git a/django-stubs/db/models/aggregates.pyi b/django-stubs/db/models/aggregates.pyi index 85eb366..1436871 100644 --- a/django-stubs/db/models/aggregates.pyi +++ b/django-stubs/db/models/aggregates.pyi @@ -40,9 +40,7 @@ class Aggregate(Func): compiler: SQLCompiler, connection: DatabaseWrapper, **extra_context: Any - ) -> Tuple[ - str, Union[List[Union[int, str]], List[Decimal], List[float]] - ]: ... + ) -> Tuple[str, Union[List[Decimal], List[int]]]: ... class Avg(Aggregate): filter: None diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index d3b6e78..6ed3099 100644 --- a/django-stubs/db/models/base.pyi +++ b/django-stubs/db/models/base.pyi @@ -1,16 +1,11 @@ from datetime import date from decimal import Decimal -from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union +from typing import Any, Dict, List, Optional, Set, Tuple, Type, Union from uuid import UUID -from django.contrib.auth.models import AbstractUser, PermissionsMixin -from django.contrib.contenttypes.fields import GenericForeignKey from django.core.checks.messages import Warning -from django.core.exceptions import (MultipleObjectsReturned, - ObjectDoesNotExist, ValidationError) -from django.db.models.fields import CharField, Field +from django.core.exceptions import ValidationError from django.db.models.fields.related import ForeignKey -from django.db.models.manager import Manager class Deferred: ... @@ -19,47 +14,17 @@ DEFERRED: Any def subclass_exception( name: str, - bases: Tuple[ - Union[Type[MultipleObjectsReturned], Type[ObjectDoesNotExist]], - Type[Exception], - ], + bases: Tuple[Type[Exception]], module: str, attached_to: Type[Model], -) -> Type[Union[MultipleObjectsReturned, ObjectDoesNotExist]]: ... +) -> Type[Exception]: ... class ModelBase(type): def __new__( cls: Type[ModelBase], name: str, bases: Tuple[Type[Model]], - attrs: Union[ - Dict[str, Any], - Dict[ - str, - Union[ - Callable, - Tuple[Tuple[int, str], Tuple[int, str]], - Field, - str, - ], - ], - Dict[str, Union[Callable, Type[Any], Field, Manager, str]], - Dict[str, Union[Callable, Type[PermissionsMixin.Meta], Field, str]], - Dict[str, Union[Callable, GenericForeignKey, Field, str]], - Dict[str, Union[Callable, Field, property, str]], - Dict[ - str, - Union[ - Tuple[ - Tuple[str, Tuple[Tuple[str, str], Tuple[str, str]]], - Tuple[str, str], - ], - CharField, - str, - ], - ], - Dict[str, Union[Type[AbstractUser.Meta], str]], - ], + attrs: Dict[str, Any], **kwargs: Any ) -> Type[Model]: ... def add_to_class(cls, name: str, value: Any) -> None: ... @@ -86,7 +51,6 @@ class Model: List[Optional[UUID]], List[Union[Decimal, int]], List[Union[int, UUID]], - List[Union[str, UUID]], Tuple[Union[int, str]], ], ) -> Model: ... diff --git a/django-stubs/db/models/expressions.pyi b/django-stubs/db/models/expressions.pyi index 2d61bd3..e44568f 100644 --- a/django-stubs/db/models/expressions.pyi +++ b/django-stubs/db/models/expressions.pyi @@ -1,19 +1,15 @@ from collections import OrderedDict -from datetime import date, datetime, time, timedelta -from decimal import Decimal +from datetime import datetime, timedelta from typing import (Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union) -from uuid import UUID from django.db.backends.sqlite3.base import DatabaseWrapper -from django.db.models.aggregates import Aggregate, Count, Sum -from django.db.models.fields import (AutoField, BinaryField, BooleanField, - DateTimeField, DurationField, Field, - IntegerField, TimeField, UUIDField) -from django.db.models.fields.mixins import FieldCacheMixin +from django.db.models.aggregates import Aggregate, Count +from django.db.models.fields import Field from django.db.models.fields.reverse_related import ForeignObjectRel from django.db.models.functions.window import DenseRank -from django.db.models.lookups import Lookup, Transform +from django.db.models.lookups import (FieldGetDbPrepValueMixin, Lookup, + Transform) from django.db.models.query import QuerySet from django.db.models.query_utils import Q from django.db.models.sql.compiler import SQLCompiler @@ -28,10 +24,7 @@ class SQLiteNumericMixin: compiler: SQLCompiler, connection: DatabaseWrapper, **extra_context: Any - ) -> Tuple[ - str, - Union[List[Union[int, str]], List[date], List[Decimal], List[float]], - ]: ... + ) -> Tuple[str, List[float]]: ... class Combinable: ADD: str = ... @@ -45,7 +38,9 @@ class Combinable: BITLEFTSHIFT: str = ... BITRIGHTSHIFT: str = ... def __neg__(self) -> CombinedExpression: ... - def __add__(self, other: Any) -> CombinedExpression: ... + def __add__( + self, other: Optional[Union[timedelta, Combinable, float, str]] + ) -> CombinedExpression: ... def __sub__( self, other: Union[timedelta, Combinable, float] ) -> CombinedExpression: ... @@ -62,7 +57,7 @@ class Combinable: def __or__(self, other: Combinable) -> Any: ... def bitor(self, other: int) -> CombinedExpression: ... def __radd__( - self, other: Optional[Union[datetime, timedelta, float]] + self, other: Optional[Union[datetime, float]] ) -> CombinedExpression: ... def __rsub__(self, other: float) -> CombinedExpression: ... def __rmul__(self, other: float) -> CombinedExpression: ... @@ -78,10 +73,7 @@ class BaseExpression: window_compatible: bool = ... output_field: Any = ... def __init__( - self, - output_field: Optional[ - Union[Field, reverse_related.ForeignObjectRel, str] - ] = ..., + self, output_field: Optional[Union[Field, ForeignObjectRel, str]] = ... ) -> None: ... def get_db_converters( self, connection: DatabaseWrapper @@ -101,13 +93,15 @@ class BaseExpression: for_save: bool = ..., ) -> BaseExpression: ... @property - def field(self) -> Union[Field, ForeignObjectRel]: ... + def field(self) -> Union[Field, reverse_related.ForeignObjectRel]: ... def output_field(self) -> Field: ... def convert_value(self) -> Callable: ... - def get_lookup(self, lookup: str) -> Optional[Type[Lookup]]: ... + def get_lookup( + self, lookup: str + ) -> Optional[Type[Union[FieldGetDbPrepValueMixin, Lookup]]]: ... def get_transform(self, name: str) -> Optional[Type[Transform]]: ... def relabeled_clone( - self, change_map: Dict[Optional[str], str] + self, change_map: Union[Dict[Optional[str], str], OrderedDict] ) -> Expression: ... def copy(self) -> BaseExpression: ... def get_group_by_cols(self) -> List[Expression]: ... @@ -138,9 +132,7 @@ class CombinedExpression(SQLiteNumericMixin, Expression): def set_source_expressions(self, exprs: List[Combinable]) -> None: ... def as_sql( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[ - str, Union[List[datetime], List[float], List[int], List[str]] - ]: ... + ) -> Tuple[str, List[float]]: ... def resolve_expression( self, query: Query = ..., @@ -229,10 +221,7 @@ class Func(SQLiteNumericMixin, Expression): template: Optional[str] = ..., arg_joiner: Optional[str] = ..., **extra_context: Any - ) -> Tuple[ - str, - Union[List[Union[int, str]], List[date], List[Decimal], List[float]], - ]: ... + ) -> Tuple[str, List[float]]: ... def copy(self) -> Func: ... class Value(Expression): @@ -242,17 +231,7 @@ class Value(Expression): ) -> None: ... def as_sql( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[ - str, - Union[ - List[date], - List[Decimal], - List[float], - List[int], - List[memoryview], - List[str], - ], - ]: ... + ) -> Tuple[str, List[float]]: ... def resolve_expression( self, query: Query = ..., @@ -281,7 +260,7 @@ class RawSQL(Expression): ) -> None: ... def as_sql( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[str, Union[List[int], List[str], Tuple]]: ... + ) -> Tuple[str, List[str]]: ... def get_group_by_cols(self) -> List[RawSQL]: ... def __hash__(self): ... @@ -308,7 +287,9 @@ class Col(Expression): def as_sql( self, compiler: SQLCompiler, connection: DatabaseWrapper ) -> Tuple[str, List[Any]]: ... - def relabeled_clone(self, relabels: Dict[str, str]) -> Col: ... + def relabeled_clone( + self, relabels: Union[Dict[str, str], OrderedDict] + ) -> Col: ... def get_group_by_cols(self) -> List[Col]: ... def get_db_converters( self, connection: DatabaseWrapper @@ -316,7 +297,9 @@ class Col(Expression): class Ref(Expression): def __init__(self, refs: str, source: Expression) -> None: ... - def get_source_expressions(self) -> List[Expression]: ... + def get_source_expressions( + self + ) -> Union[List[Expression], List[SQLiteNumericMixin]]: ... def set_source_expressions(self, exprs: Any) -> None: ... def resolve_expression( self, @@ -350,7 +333,7 @@ class ExpressionWrapper(Expression): ) -> Union[List[CombinedExpression], List[Node]]: ... def as_sql( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[str, Union[List[int], List[str]]]: ... + ) -> Tuple[str, List[Any]]: ... class When(Expression): template: str = ... @@ -378,17 +361,7 @@ class When(Expression): connection: DatabaseWrapper, template: None = ..., **extra_context: Any - ) -> Tuple[ - str, - Union[ - List[Union[date, int]], - List[Union[date, str]], - List[Union[Decimal, int]], - List[Union[int, memoryview]], - List[Union[int, str]], - List[float], - ], - ]: ... + ) -> Tuple[str, List[Union[int, str]]]: ... def get_group_by_cols(self) -> List[Col]: ... class Case(Expression): @@ -422,17 +395,7 @@ class Case(Expression): template: None = ..., case_joiner: None = ..., **extra_context: Any - ) -> Tuple[ - str, - Union[ - List[Union[date, int]], - List[Union[date, str]], - List[Union[Decimal, int]], - List[Union[int, memoryview]], - List[Union[int, str]], - List[float], - ], - ]: ... + ) -> Tuple[str, List[Union[int, str]]]: ... class Subquery(Expression): template: str = ... @@ -512,10 +475,10 @@ class OrderBy(BaseExpression): connection: DatabaseWrapper, template: Optional[str] = ..., **extra_context: Any - ) -> Tuple[str, Union[List[Union[int, str]], Tuple]]: ... + ) -> Tuple[str, List[Union[int, str]]]: ... def as_sqlite( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[str, Union[List[Union[int, str]], Tuple]]: ... + ) -> Tuple[str, List[Union[int, str]]]: ... def as_mysql(self, compiler: Any, connection: Any): ... def get_group_by_cols(self): ... def reverse_ordering(self) -> OrderBy: ... diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index 3eeedc8..87da46e 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -3,7 +3,6 @@ from decimal import Context, Decimal from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union from uuid import UUID -from django.contrib.auth.validators import UnicodeUsernameValidator from django.core.exceptions import FieldDoesNotExist as FieldDoesNotExist from django.core.validators import DecimalValidator from django.db.backends.sqlite3.base import DatabaseWrapper @@ -79,30 +78,9 @@ class Field(RegisterLookupMixin): choices: Optional[ Union[ List[List[Union[List[List[str]], str]]], - List[ - Tuple[ - Union[int, str], - Union[ - Tuple[ - Tuple[str, str], - Tuple[str, str], - Tuple[str, str], - ], - Tuple[Tuple[str, str], Tuple[str, str]], - int, - str, - ], - ] - ], - Tuple[ - Union[ - Tuple[int, Union[int, str]], - Tuple[ - str, - Union[Tuple[Tuple[int, str], Tuple[int, str]], str], - ], - ] - ], + List[Tuple[Optional[int], str]], + List[Tuple[Union[int, str], int]], + Tuple[Tuple[Union[int, str], Union[int, str]]], ] ] = ..., help_text: str = ..., @@ -116,7 +94,9 @@ class Field(RegisterLookupMixin): def get_col( self, alias: str, - output_field: Optional[Union[Field, ForeignObjectRel]] = ..., + output_field: Optional[ + Union[Field, reverse_related.ForeignObjectRel] + ] = ..., ) -> Col: ... def cached_col(self) -> Col: ... def select_format( @@ -124,81 +104,14 @@ class Field(RegisterLookupMixin): ) -> Tuple[str, List[Union[int, str]]]: ... def deconstruct( self - ) -> Union[ - Tuple[None, str, List[Any], Dict[str, Union[List[Callable], int, str]]], - Tuple[ - str, - List[Any], - Union[ - Dict[str, Optional[bool]], - Dict[str, Union[Callable, int, str]], - Dict[str, Union[List[Tuple[int, str]], int]], - Dict[ - str, - Union[ - List[ - Tuple[ - str, - Union[ - Tuple[Tuple[str, str], Tuple[str, str]], str - ], - ] - ], - int, - ], - ], - Dict[str, Union[List[Tuple[str, str]], int]], - Dict[str, Union[List[UnicodeUsernameValidator], int, str]], - Dict[str, float], - ], - Union[ - Dict[str, Optional[bool]], - Dict[str, Union[Callable, int, str]], - Dict[str, Union[List[Tuple[int, str]], int]], - Dict[ - str, - Union[ - List[ - Tuple[ - str, - Union[ - Tuple[Tuple[str, str], Tuple[str, str]], str - ], - ] - ], - int, - ], - ], - Dict[str, Union[List[Tuple[str, str]], int]], - Dict[str, Union[List[UnicodeUsernameValidator], int, str]], - Dict[str, float], - ], - ], - Tuple[ - str, - List[Any], - Union[ - Dict[str, Optional[bool]], - Dict[str, Union[List[Tuple[int, str]], str]], - ], - Union[ - Dict[str, List[Tuple[int, str]]], - Dict[str, Optional[bool]], - Dict[str, Union[List[Tuple[int, str]], str]], - ], - ], + ) -> Tuple[ + Optional[str], str, List[Any], Dict[str, List[Tuple[int, str]]] ]: ... def clone(self) -> Field: ... def __eq__(self, other: Field) -> bool: ... def __lt__(self, other: Field) -> bool: ... def __hash__(self) -> int: ... - def __deepcopy__( - self, - memodict: Union[ - Dict[int, Any], - Dict[int, Union[Dict[str, Field], List[Field], Field]], - ], - ) -> Field: ... + def __deepcopy__(self, memodict: Dict[int, Dict[Any, Any]]) -> Field: ... def __copy__(self) -> Field: ... def __reduce__(self): ... def get_pk_value_on_save(self, instance: Model) -> Optional[UUID]: ... @@ -242,7 +155,7 @@ class Field(RegisterLookupMixin): ) -> Optional[Union[bytes, float, str]]: ... def get_db_prep_save( self, value: Any, connection: DatabaseWrapper - ) -> Optional[Union[float, memoryview, str]]: ... + ) -> Optional[Union[float, str]]: ... def has_default(self) -> bool: ... def get_default(self) -> Any: ... def get_choices( @@ -251,20 +164,8 @@ class Field(RegisterLookupMixin): blank_choice: List[Tuple[str, str]] = ..., limit_choices_to: Optional[Dict[str, QuerySet]] = ..., ) -> List[ - Union[ - Tuple[ - Union[ - Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str]], - Tuple[Tuple[str, str], Tuple[str, str]], - str, - ], - Union[ - Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str]], - Tuple[Tuple[str, str], Tuple[str, str]], - str, - ], - ], - Tuple[int, int], + Tuple[ + Union[int, str], Union[Tuple[Tuple[str, str], Tuple[str, str]], str] ] ]: ... def value_to_string(self, obj: Model) -> str: ... @@ -274,7 +175,7 @@ class Field(RegisterLookupMixin): ) -> None: ... def formfield( self, - form_class: Optional[Type[Any]] = ..., + form_class: Optional[Type[Field]] = ..., choices_form_class: Optional[Type[TypedMultipleChoiceField]] = ..., **kwargs: Any ) -> Field: ... @@ -288,15 +189,7 @@ class AutoField(Field): def check(self, **kwargs: Any) -> List[Any]: ... def deconstruct( self - ) -> Union[ - Tuple[ - str, - List[Any], - Dict[str, Union[bool, str]], - Dict[str, Union[bool, str]], - ], - Tuple[str, str, List[Any], Dict[str, bool]], - ]: ... + ) -> Tuple[Optional[str], str, List[Any], Dict[str, Union[bool, str]]]: ... def get_internal_type(self) -> str: ... def to_python(self, value: Union[int, str]) -> int: ... def rel_db_type(self, connection: DatabaseWrapper) -> str: ... @@ -367,14 +260,8 @@ class DateField(DateTimeCheckMixin, Field): ) -> None: ... def deconstruct( self - ) -> Union[ - Tuple[ - str, - List[Any], - Dict[str, Union[Callable, int, str]], - Dict[str, Union[Callable, int, str]], - ], - Tuple[str, str, List[Any], Dict[str, int]], + ) -> Tuple[ + Optional[str], str, List[Any], Dict[str, Union[Callable, int, str]] ]: ... def get_internal_type(self) -> str: ... def to_python( @@ -438,7 +325,7 @@ class DecimalField(Field): def context(self) -> Context: ... def deconstruct( self - ) -> Tuple[str, List[Any], Dict[str, int], Dict[str, int]]: ... + ) -> Tuple[Optional[str], str, List[Any], Dict[str, int]]: ... def get_internal_type(self) -> str: ... def to_python(self, value: Optional[str]) -> Optional[Decimal]: ... def get_db_prep_save( @@ -466,7 +353,7 @@ class EmailField(CharField): def __init__(self, *args: Any, **kwargs: Any) -> None: ... def deconstruct( self - ) -> Tuple[str, List[Any], Dict[str, int], Dict[str, int]]: ... + ) -> Tuple[Optional[str], str, List[Any], Dict[str, int]]: ... def formfield(self, **kwargs: Any) -> EmailField: ... class FilePathField(Field): @@ -588,15 +475,7 @@ class SlugField(CharField): ) -> None: ... def deconstruct( self - ) -> Union[ - Tuple[ - str, - List[Any], - Dict[str, int], - Union[Dict[Any, Any], Dict[str, int]], - ], - Tuple[str, str, List[Any], Dict[str, int]], - ]: ... + ) -> Tuple[Optional[str], str, List[Any], Dict[str, int]]: ... def get_internal_type(self) -> str: ... def formfield(self, **kwargs: Any) -> SlugField: ... @@ -629,20 +508,18 @@ class TimeField(DateTimeCheckMixin, Field): ) -> None: ... def deconstruct( self - ) -> Tuple[str, List[Any], Dict[Any, Any], Dict[Any, Any]]: ... + ) -> Tuple[Optional[str], str, List[Any], Dict[Any, Any]]: ... def get_internal_type(self) -> str: ... def to_python( - self, value: Optional[Union[datetime, time, str]] + self, value: Optional[Union[datetime, str]] ) -> Optional[time]: ... def pre_save( self, model_instance: Model, add: bool ) -> Optional[datetime]: ... - def get_prep_value( - self, value: Optional[Union[datetime, time]] - ) -> Optional[time]: ... + def get_prep_value(self, value: Optional[datetime]) -> Optional[time]: ... def get_db_prep_value( self, - value: Optional[Union[datetime, time]], + value: Optional[datetime], connection: DatabaseWrapper, prepared: bool = ..., ) -> Optional[str]: ... @@ -657,9 +534,7 @@ class URLField(CharField): ) -> None: ... def deconstruct( self - ) -> Tuple[ - str, List[Any], Dict[str, int], Union[Dict[Any, Any], Dict[str, int]] - ]: ... + ) -> Tuple[Optional[str], str, List[Any], Dict[str, int]]: ... def formfield(self, **kwargs: Any) -> URLField: ... class BinaryField(Field): @@ -668,19 +543,11 @@ class BinaryField(Field): def __init__(self, *args: Any, **kwargs: Any) -> None: ... def deconstruct( self - ) -> Union[ - Tuple[ - str, - List[Any], - Dict[str, bool], - Union[Dict[Any, Any], Dict[str, bool]], - ], - Tuple[str, str, List[Any], Dict[Any, Any]], - ]: ... + ) -> Tuple[Optional[str], str, List[Any], Dict[str, bool]]: ... def get_internal_type(self) -> str: ... def get_placeholder( self, - value: Optional[memoryview], + value: None, compiler: SQLInsertCompiler, connection: DatabaseWrapper, ) -> str: ... @@ -690,7 +557,7 @@ class BinaryField(Field): value: Optional[bytes], connection: DatabaseWrapper, prepared: bool = ..., - ) -> Optional[memoryview]: ... + ) -> None: ... def value_to_string(self, obj: Any): ... def to_python(self, value: Any): ... @@ -702,10 +569,7 @@ class UUIDField(Field): def deconstruct( self ) -> Tuple[ - str, - List[Any], - Dict[str, Union[Callable, bool]], - Dict[str, Union[Callable, bool]], + Optional[str], str, List[Any], Dict[str, Union[Callable, bool]] ]: ... def get_internal_type(self) -> str: ... def get_db_prep_value( diff --git a/django-stubs/db/models/fields/files.pyi b/django-stubs/db/models/fields/files.pyi index 04f818f..2b5d785 100644 --- a/django-stubs/db/models/fields/files.pyi +++ b/django-stubs/db/models/fields/files.pyi @@ -12,10 +12,7 @@ from django.forms.fields import FileField, ImageField class FieldFile(File): instance: django.db.models.base.Model = ... field: django.db.models.fields.files.FileField = ... - storage: Union[ - django.core.files.storage.DefaultStorage, - django.core.files.storage.FileSystemStorage, - ] = ... + storage: django.core.files.storage.FileSystemStorage = ... def __init__( self, instance: Model, field: FileField, name: Optional[str] ) -> None: ... @@ -63,18 +60,7 @@ class FileField(Field): def check(self, **kwargs: Any) -> List[Error]: ... def deconstruct( self - ) -> Tuple[ - str, - List[Any], - Union[ - Dict[str, Union[Callable, FileSystemStorage, int]], - Dict[str, Union[FileSystemStorage, int, str]], - ], - Union[ - Dict[str, Union[Callable, FileSystemStorage, int]], - Dict[str, Union[FileSystemStorage, int, str]], - ], - ]: ... + ) -> Tuple[Optional[str], str, List[Any], Dict[str, Union[bool, str]]]: ... def get_internal_type(self) -> str: ... def get_prep_value(self, value: Union[FieldFile, str]) -> str: ... def pre_save(self, model_instance: Model, add: bool) -> FieldFile: ... @@ -116,10 +102,10 @@ class ImageField(FileField): def deconstruct( self ) -> Tuple[ + Optional[str], str, List[Any], Dict[str, Union[Callable, bool, FileSystemStorage, str]], - Dict[str, Union[Callable, bool, FileSystemStorage, str]], ]: ... def contribute_to_class( self, cls: Type[Model], name: str, **kwargs: Any diff --git a/django-stubs/db/models/fields/related.pyi b/django-stubs/db/models/fields/related.pyi index 5ece72c..b5ab984 100644 --- a/django-stubs/db/models/fields/related.pyi +++ b/django-stubs/db/models/fields/related.pyi @@ -3,13 +3,14 @@ from uuid import UUID from django.core.checks.messages import Error, Warning from django.db.backends.sqlite3.base import DatabaseWrapper -from django.db.migrations.writer import SettingsReference from django.db.models.base import Model from django.db.models.expressions import Col from django.db.models.fields import Field +from django.db.models.fields.related_lookups import RelatedIsNull from django.db.models.fields.reverse_related import (ForeignObjectRel, ManyToManyRel, ManyToOneRel, OneToOneRel) +from django.db.models.lookups import FieldGetDbPrepValueMixin from django.db.models.query import QuerySet from django.db.models.query_utils import PathInfo, Q from django.db.models.sql.where import WhereNode @@ -57,23 +58,10 @@ class RelatedField(FieldCacheMixin, Field): ) -> None: ... def deconstruct( self - ) -> Tuple[ - str, - List[Any], - Union[ - Dict[str, Union[Callable, bool, str]], - Dict[str, Union[Dict[str, Union[int, str]], bool]], - Dict[str, Union[Dict[str, bool], bool, str]], - ], - Union[ - Dict[str, Union[Callable, bool, str]], - Dict[str, Union[Dict[str, Union[int, str]], bool]], - Dict[str, Union[Dict[str, bool], bool, str]], - ], - ]: ... + ) -> Tuple[Optional[str], str, List[Any], Dict[str, str]]: ... def get_forward_related_filter( self, obj: Model - ) -> Union[Dict[str, int], Dict[str, UUID]]: ... + ) -> Dict[str, Union[int, UUID]]: ... def get_reverse_related_filter(self, obj: Model) -> Q: ... @property def swappable_setting(self) -> Optional[str]: ... @@ -119,18 +107,19 @@ class ForeignObject(RelatedField): def check(self, **kwargs: Any) -> List[Any]: ... def deconstruct( self - ) -> Union[ - Tuple[None, str, List[Any], Dict[str, Any]], - Tuple[str, List[Any], Dict[str, Any], Dict[str, Any]], - Tuple[ + ) -> Tuple[ + Optional[str], + str, + List[Any], + Dict[ str, - str, - List[Any], - Dict[ + Union[ + Callable, + Dict[str, Union[int, str]], + List[None], + List[str], + bool, str, - Union[ - Callable, Dict[str, Union[int, str]], List[str], bool, str - ], ], ], ]: ... @@ -145,14 +134,14 @@ class ForeignObject(RelatedField): def foreign_related_fields(self) -> Tuple[Field]: ... def get_local_related_value( self, instance: Model - ) -> Tuple[Optional[Union[int, str, UUID]]]: ... + ) -> Tuple[Optional[int]]: ... def get_foreign_related_value( self, instance: Model - ) -> Tuple[Optional[Union[int, str, UUID]]]: ... + ) -> Tuple[Optional[int]]: ... @staticmethod def get_instance_value_for_fields( instance: Model, fields: Tuple[Field] - ) -> Tuple[Optional[Union[int, str, UUID]]]: ... + ) -> Tuple[Optional[int]]: ... def get_attname_column(self) -> Tuple[str, None]: ... def get_joining_columns( self, reverse_join: bool = ... @@ -169,7 +158,9 @@ class ForeignObject(RelatedField): ) -> List[PathInfo]: ... def get_reverse_path_info(self, filtered_relation: Optional[Any] = ...): ... @classmethod - def get_lookups(cls) -> Dict[str, Type[Any]]: ... + def get_lookups( + cls + ) -> Dict[str, Type[Union[RelatedIsNull, FieldGetDbPrepValueMixin]]]: ... def contribute_to_class( self, cls: Type[Model], @@ -208,33 +199,11 @@ class ForeignKey(ForeignObject): def check(self, **kwargs: Any) -> List[Warning]: ... def deconstruct( self - ) -> Union[ - Tuple[ - None, - str, - List[Any], - Dict[str, Union[Callable, Dict[str, Union[int, str]], str]], - ], - Tuple[ - str, - List[Any], - Union[ - Dict[str, Union[Callable, Dict[str, Union[int, str]], str]], - Dict[str, Union[Callable, Dict[str, bool], str]], - Dict[str, Union[Callable, bool, str]], - ], - Union[ - Dict[str, Union[Callable, Dict[str, Union[int, str]], str]], - Dict[str, Union[Callable, Dict[str, bool], str]], - Dict[str, Union[Callable, bool, str]], - ], - ], - Tuple[ - str, - str, - List[Any], - Dict[str, Union[Callable, bool, SettingsReference]], - ], + ) -> Tuple[ + Optional[str], + str, + List[Any], + Dict[str, Union[Callable, Dict[str, Union[int, str]], str]], ]: ... def to_python(self, value: Union[int, str]) -> int: ... @property @@ -277,7 +246,7 @@ class ForeignKey(ForeignObject): def get_col( self, alias: str, - output_field: Optional[Union[Field, OneToOneRel]] = ..., + output_field: Optional[Union[Field, reverse_related.OneToOneRel]] = ..., ) -> Col: ... class OneToOneField(ForeignKey): @@ -299,10 +268,7 @@ class OneToOneField(ForeignKey): def deconstruct( self ) -> Tuple[ - str, - List[Any], - Dict[str, Union[Callable, bool, str]], - Dict[str, Union[Callable, bool, str]], + Optional[str], str, List[Any], Dict[str, Union[Callable, bool, str]] ]: ... def formfield(self, **kwargs: Any) -> None: ... def save_form_data( @@ -338,20 +304,7 @@ class ManyToManyField(RelatedField): def check(self, **kwargs: Any) -> List[Any]: ... def deconstruct( self - ) -> Union[ - Tuple[None, str, List[Any], Dict[str, Union[bool, str]]], - Tuple[ - str, - List[Any], - Union[Dict[str, Union[Callable, str]], Dict[str, Union[bool, str]]], - Union[ - Dict[str, Union[Callable, str]], - Dict[str, Union[bool, str]], - Dict[str, str], - ], - ], - Tuple[str, str, List[Any], Dict[str, Union[Callable, str]]], - ]: ... + ) -> Tuple[Optional[str], str, List[Any], Dict[str, str]]: ... def get_path_info( self, filtered_relation: None = ... ) -> List[PathInfo]: ... diff --git a/django-stubs/db/models/fields/related_lookups.pyi b/django-stubs/db/models/fields/related_lookups.pyi index e72cb47..3ec926a 100644 --- a/django-stubs/db/models/fields/related_lookups.pyi +++ b/django-stubs/db/models/fields/related_lookups.pyi @@ -4,11 +4,12 @@ from uuid import UUID from django.db.backends.sqlite3.base import DatabaseWrapper from django.db.models.base import Model -from django.db.models.expressions import Col, OuterRef +from django.db.models.expressions import Col from django.db.models.fields import Field from django.db.models.fields.related import ForeignObject -from django.db.models.lookups import (Exact, GreaterThan, GreaterThanOrEqual, - In, IsNull, LessThan, LessThanOrEqual) +from django.db.models.lookups import (BuiltinLookup, Exact, GreaterThan, + GreaterThanOrEqual, In, IsNull, LessThan, + LessThanOrEqual) from django.db.models.sql.compiler import SQLCompiler from django.db.models.sql.query import Query @@ -28,13 +29,11 @@ class MultiColSource: field: related.ForeignObject, ) -> None: ... def relabeled_clone(self, relabels: OrderedDict) -> MultiColSource: ... - def get_lookup( - self, lookup: str - ) -> Type[Union[RelatedExact, RelatedIn, RelatedIsNull]]: ... + def get_lookup(self, lookup: str) -> Type[BuiltinLookup]: ... def get_normalized_value( value: Any, lhs: Union[Col, MultiColSource] -) -> Tuple[Optional[Union[OuterRef, int, str, UUID]]]: ... +) -> Tuple[None]: ... class RelatedIn(In): bilateral_transforms: List[Any] @@ -44,8 +43,8 @@ class RelatedIn(In): django.db.models.fields.related_lookups.MultiColSource, ] rhs: Union[ - List[Union[django.db.models.base.Model, int]], - List[Union[int, str]], + List[django.db.models.base.Model], + List[int], List[uuid.UUID], Set[django.contrib.contenttypes.models.ContentType], Set[int], @@ -58,7 +57,7 @@ class RelatedIn(In): ) -> Union[List[Model], List[int], List[str], List[UUID], Query]: ... def as_sql( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[str, Union[List[int], List[str]]]: ... + ) -> Tuple[str, List[Any]]: ... class RelatedLookupMixin: rhs: Any = ... diff --git a/django-stubs/db/models/fields/reverse_related.pyi b/django-stubs/db/models/fields/reverse_related.pyi index d2434a2..8257755 100644 --- a/django-stubs/db/models/fields/reverse_related.pyi +++ b/django-stubs/db/models/fields/reverse_related.pyi @@ -4,9 +4,7 @@ from django.db.models.base import Model from django.db.models.fields import AutoField, Field from django.db.models.fields.related import (ForeignKey, OneToOneField, RelatedField) -from django.db.models.fields.related_lookups import (RelatedExact, RelatedIn, - RelatedIsNull) -from django.db.models.lookups import StartsWith +from django.db.models.lookups import BuiltinLookup, StartsWith from django.db.models.query_utils import FilteredRelation, PathInfo, Q from django.db.models.sql.where import WhereNode @@ -58,9 +56,7 @@ class ForeignObjectRel(FieldCacheMixin): def many_to_one(self) -> bool: ... def one_to_many(self) -> bool: ... def one_to_one(self) -> bool: ... - def get_lookup( - self, lookup_name: str - ) -> Type[Union[RelatedExact, RelatedIn, RelatedIsNull]]: ... + def get_lookup(self, lookup_name: str) -> Type[BuiltinLookup]: ... def get_internal_type(self) -> str: ... @property def db_type(self) -> Callable: ... diff --git a/django-stubs/db/models/functions/comparison.pyi b/django-stubs/db/models/functions/comparison.pyi index 1d52454..6ee90ed 100644 --- a/django-stubs/db/models/functions/comparison.pyi +++ b/django-stubs/db/models/functions/comparison.pyi @@ -26,7 +26,7 @@ class Cast(Func): compiler: SQLCompiler, connection: DatabaseWrapper, **extra_context: Any - ) -> Tuple[str, Union[List[date], List[Decimal], List[str]]]: ... + ) -> Tuple[str, Union[List[date], List[Decimal]]]: ... def as_mysql(self, compiler: Any, connection: Any): ... def as_postgresql(self, compiler: Any, connection: Any): ... diff --git a/django-stubs/db/models/functions/datetime.pyi b/django-stubs/db/models/functions/datetime.pyi index 5e373dd..13b84e3 100644 --- a/django-stubs/db/models/functions/datetime.pyi +++ b/django-stubs/db/models/functions/datetime.pyi @@ -1,10 +1,10 @@ -from datetime import date, time +from datetime import datetime from typing import Any, List, Optional, Set, Tuple, Union from django.db.backends.sqlite3.base import DatabaseWrapper from django.db.models import Func, Transform from django.db.models.expressions import Col, Expression -from django.db.models.fields import DateTimeCheckMixin, IntegerField +from django.db.models.fields import Field from django.db.models.sql.compiler import SQLCompiler from django.db.models.sql.query import Query @@ -138,7 +138,7 @@ class TruncBase(TimezoneMixin, Transform): def __init__( self, expression: Union[Col, str], - output_field: Optional[Union[DateTimeCheckMixin, IntegerField]] = ..., + output_field: Optional[Field] = ..., tzinfo: None = ..., **extra: Any ) -> None: ... @@ -155,16 +155,19 @@ class TruncBase(TimezoneMixin, Transform): ) -> TruncBase: ... def convert_value( self, - value: Union[date, time], + value: datetime, expression: django.db.models.functions.TruncBase, connection: DatabaseWrapper, - ) -> Union[date, time]: ... + ) -> datetime: ... class Trunc(TruncBase): contains_aggregate: bool extra: Dict[Any, Any] is_summary: bool - output_field: django.db.models.fields.Field + output_field: Union[ + django.db.models.fields.DateTimeCheckMixin, + django.db.models.fields.IntegerField, + ] source_expressions: List[django.db.models.expressions.Combinable] tzinfo: None kind: str = ... @@ -172,7 +175,7 @@ class Trunc(TruncBase): self, expression: str, kind: str, - output_field: Optional[Union[DateTimeCheckMixin, IntegerField]] = ..., + output_field: Optional[Field] = ..., tzinfo: None = ..., **extra: Any ) -> None: ... diff --git a/django-stubs/db/models/functions/text.pyi b/django-stubs/db/models/functions/text.pyi index 4f9996f..de3378e 100644 --- a/django-stubs/db/models/functions/text.pyi +++ b/django-stubs/db/models/functions/text.pyi @@ -144,7 +144,7 @@ class Ord(Transform): compiler: SQLCompiler, connection: DatabaseWrapper, **extra_context: Any - ) -> Tuple[str, Union[List[int], List[str]]]: ... + ) -> Tuple[str, List[Any]]: ... class Repeat(BytesToCharFieldConversionMixin, Func): contains_aggregate: bool diff --git a/django-stubs/db/models/lookups.pyi b/django-stubs/db/models/lookups.pyi index 56764f8..a5a551a 100644 --- a/django-stubs/db/models/lookups.pyi +++ b/django-stubs/db/models/lookups.pyi @@ -1,5 +1,5 @@ -from datetime import date, datetime -from decimal import Decimal +from collections import OrderedDict +from datetime import datetime from typing import Any, Dict, List, Optional, Tuple, Type, Union from uuid import UUID @@ -13,6 +13,7 @@ from django.db.models.query_utils import RegisterLookupMixin from django.db.models.sql.compiler import SQLCompiler from django.db.models.sql.query import Query from django.utils.datastructures import OrderedSet +from django.utils.safestring import SafeText class Lookup: @@ -22,7 +23,9 @@ class Lookup: rhs: Any = ... bilateral_transforms: Any = ... def __init__( - self, lhs: Union[Expression, TextField, MultiColSource], rhs: Any + self, + lhs: Union[Expression, TextField, related_lookups.MultiColSource], + rhs: Any, ) -> None: ... def apply_bilateral_transforms(self, value: Expression) -> Transform: ... def batch_process_rhs( @@ -30,40 +33,26 @@ class Lookup: compiler: SQLCompiler, connection: DatabaseWrapper, rhs: Optional[OrderedSet] = ..., - ) -> Tuple[ - List[str], - Union[List[Optional[int]], List[Union[Combinable, int]], List[str]], - ]: ... + ) -> Tuple[List[str], List[str]]: ... def get_source_expressions(self) -> List[Expression]: ... lhs: Any = ... def set_source_expressions(self, new_exprs: List[Ref]) -> None: ... def get_prep_lookup(self) -> Any: ... def get_db_prep_lookup( self, value: Union[int, str], connection: DatabaseWrapper - ) -> Tuple[str, Union[List[int], List[str]]]: ... + ) -> Tuple[str, List[SafeText]]: ... def process_lhs( self, compiler: SQLCompiler, connection: DatabaseWrapper, lhs: Optional[Col] = ..., - ) -> Tuple[str, Union[List[Union[int, str]], Tuple]]: ... + ) -> Tuple[str, List[Union[int, str]]]: ... def process_rhs( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[ - str, - Union[ - List[None], - List[Union[date, str]], - List[Union[int, str]], - List[Decimal], - List[float], - List[memoryview], - Tuple, - ], - ]: ... + ) -> Tuple[str, Union[List[Union[int, str]], Tuple[int, int]]]: ... def rhs_is_direct_value(self) -> bool: ... def relabeled_clone( - self, relabels: Dict[Optional[str], str] + self, relabels: Union[Dict[Optional[str], str], OrderedDict] ) -> Union[BuiltinLookup, FieldGetDbPrepValueMixin]: ... def get_group_by_cols(self) -> List[Expression]: ... def as_sql(self, compiler: Any, connection: Any) -> None: ... @@ -88,44 +77,24 @@ class BuiltinLookup(Lookup): ) -> Tuple[str, List[Union[int, str]]]: ... def as_sql( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[ - str, - Union[ - List[Optional[int]], - List[Union[date, str]], - List[Union[Decimal, int]], - List[Union[int, str]], - List[float], - List[memoryview], - ], - ]: ... + ) -> Tuple[str, List[float]]: ... def get_rhs_op(self, connection: DatabaseWrapper, rhs: str) -> str: ... class FieldGetDbPrepValueMixin: get_db_prep_lookup_value_is_iterable: bool = ... def get_db_prep_lookup( self, value: Any, connection: DatabaseWrapper - ) -> Tuple[ - str, - Union[ - List[Optional[int]], - List[Union[Combinable, int]], - List[Decimal], - List[float], - List[memoryview], - List[str], - ], - ]: ... + ) -> Tuple[str, List[float]]: ... class FieldGetDbPrepValueIterableMixin(FieldGetDbPrepValueMixin): get_db_prep_lookup_value_is_iterable: bool = ... def get_prep_lookup( self ) -> Union[ - List[Optional[int]], - List[Union[Combinable, int]], List[datetime], List[Model], + List[Combinable], + List[int], List[str], List[UUID], Subquery, @@ -133,14 +102,14 @@ class FieldGetDbPrepValueIterableMixin(FieldGetDbPrepValueMixin): ]: ... def process_rhs( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[Tuple, Tuple]: ... + ) -> Tuple[Union[Tuple[str, str], str], Tuple]: ... def resolve_expression_parameter( self, compiler: SQLCompiler, connection: DatabaseWrapper, sql: str, param: Optional[Union[Combinable, int, str]], - ) -> Tuple[str, Union[List[None], List[int], List[str]]]: ... + ) -> Tuple[str, List[None]]: ... def batch_process_rhs( self, compiler: SQLCompiler, @@ -157,17 +126,7 @@ class Exact(FieldGetDbPrepValueMixin, BuiltinLookup): lookup_name: str = ... def process_rhs( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[ - str, - Union[ - List[None], - List[Union[int, str]], - List[Decimal], - List[float], - List[memoryview], - Tuple, - ], - ]: ... + ) -> Tuple[str, Union[List[str], Tuple[int, int]]]: ... class IExact(BuiltinLookup): bilateral_transforms: List[Any] @@ -183,10 +142,7 @@ class IExact(BuiltinLookup): class GreaterThan(FieldGetDbPrepValueMixin, BuiltinLookup): bilateral_transforms: List[Any] contains_aggregate: bool - lhs: Union[ - django.db.models.expressions.Expression, - django.db.models.expressions.SQLiteNumericMixin, - ] + lhs: django.db.models.expressions.Expression rhs: Any lookup_name: str = ... @@ -194,24 +150,33 @@ class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup): bilateral_transforms: List[Any] contains_aggregate: bool lhs: django.db.models.expressions.Expression - rhs: Any + rhs: Union[ + datetime.datetime, + decimal.Decimal, + django.db.models.expressions.Combinable, + int, + str, + ] lookup_name: str = ... class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup): bilateral_transforms: List[Any] contains_aggregate: bool lhs: django.db.models.expressions.Expression - rhs: Any + rhs: Union[ + datetime.datetime, + decimal.Decimal, + django.db.models.expressions.CombinedExpression, + float, + str, + ] lookup_name: str = ... class LessThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup): bilateral_transforms: List[Type[django.db.models.lookups.Transform]] contains_aggregate: bool contains_over_clause: bool - lhs: Union[ - django.db.models.expressions.Expression, - django.db.models.expressions.SQLiteNumericMixin, - ] + lhs: django.db.models.expressions.Expression rhs: Union[ datetime.date, decimal.Decimal, @@ -241,7 +206,7 @@ class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup): def get_rhs_op(self, connection: DatabaseWrapper, rhs: str) -> str: ... def as_sql( self, compiler: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[str, Union[List[Optional[int]], List[Union[int, str]]]]: ... + ) -> Tuple[str, List[Union[int, str]]]: ... def split_parameter_list_as_sql(self, compiler: Any, connection: Any): ... class PatternLookup(BuiltinLookup): @@ -250,7 +215,7 @@ class PatternLookup(BuiltinLookup): def get_rhs_op(self, connection: DatabaseWrapper, rhs: str) -> str: ... def process_rhs( self, qn: SQLCompiler, connection: DatabaseWrapper - ) -> Tuple[str, Union[List[int], List[str]]]: ... + ) -> Tuple[str, List[Any]]: ... class Contains(PatternLookup): bilateral_transforms: List[Type[django.db.models.lookups.Transform]] @@ -301,13 +266,11 @@ class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup): contains_aggregate: bool lhs: django.db.models.expressions.Expression rhs: Union[ - List[Union[django.db.models.expressions.Combinable, int]], List[datetime.datetime], Tuple[ - Union[django.db.models.expressions.Combinable, int], - Union[django.db.models.expressions.CombinedExpression, int], + Union[django.db.models.expressions.F, int], + Union[datetime.datetime, int], ], - Tuple[datetime.datetime, datetime.datetime], ] lookup_name: str = ... def get_rhs_op( diff --git a/django-stubs/db/models/manager.pyi b/django-stubs/db/models/manager.pyi index 0ad9a5e..526bcd6 100644 --- a/django-stubs/db/models/manager.pyi +++ b/django-stubs/db/models/manager.pyi @@ -1,6 +1,5 @@ -from typing import Any, Dict, List, Optional, Tuple, Type, Union +from typing import Any, Dict, List, Optional, Tuple, Type -from django.contrib.auth.models import Group, Permission from django.contrib.sites.managers import CurrentSiteManager from django.db.models.base import Model from django.db.models.query import QuerySet @@ -45,13 +44,6 @@ class ManagerDescriptor: class EmptyManager(Manager): creation_counter: int name: None - model: Optional[ - Type[ - Union[ - django.contrib.auth.models.Group, - django.contrib.auth.models.Permission, - ] - ] - ] = ... - def __init__(self, model: Type[Union[Group, Permission]]) -> None: ... + model: Optional[Type[django.db.models.base.Model]] = ... + def __init__(self, model: Type[Model]) -> None: ... def get_queryset(self) -> QuerySet: ... diff --git a/django-stubs/db/models/options.pyi b/django-stubs/db/models/options.pyi index c691558..effa094 100644 --- a/django-stubs/db/models/options.pyi +++ b/django-stubs/db/models/options.pyi @@ -33,7 +33,7 @@ def make_immutable_fields_list( data: Union[ Iterator[Any], List[Union[ArrayField, CIText]], - List[Union[Field, mixins.FieldCacheMixin]], + List[Union[Field, FieldCacheMixin]], ], ) -> ImmutableList: ... @@ -121,9 +121,8 @@ class Options: @property def installed(self): ... model: Type[django.db.models.base.Model] = ... - original_attrs: Union[ - Dict[str, Union[List[str], str]], - Dict[str, Union[django.apps.registry.Apps, str]], + original_attrs: Dict[ + str, Union[List[str], django.apps.registry.Apps, str] ] = ... def contribute_to_class(self, cls: Type[Model], name: str) -> None: ... def add_manager(self, manager: Manager) -> None: ... @@ -149,7 +148,7 @@ class Options: def fields_map(self) -> Dict[str, ForeignObjectRel]: ... def get_field( self, field_name: Union[Callable, str] - ) -> Union[Field, FieldCacheMixin]: ... + ) -> Union[Field, mixins.FieldCacheMixin]: ... def get_base_chain(self, model: Type[Model]) -> List[Type[Model]]: ... def get_parent_list(self) -> List[Type[Model]]: ... def get_ancestor_link( diff --git a/django-stubs/db/models/query.pyi b/django-stubs/db/models/query.pyi index 01e29a2..de1bf2e 100644 --- a/django-stubs/db/models/query.pyi +++ b/django-stubs/db/models/query.pyi @@ -1,17 +1,17 @@ -from datetime import date, datetime, time, timedelta +from collections import OrderedDict +from datetime import date, datetime from decimal import Decimal from itertools import chain -from typing import (Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, - Union) +from typing import (Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, + Type, Union) from unittest.mock import MagicMock from uuid import UUID -from django.contrib.auth.models import Permission, User from django.contrib.contenttypes.fields import GenericForeignKey -from django.contrib.contenttypes.models import ContentType from django.db.models.base import Model, ModelState from django.db.models.expressions import Expression from django.db.models.fields import Field +from django.db.models.fields.mixins import FieldCacheMixin from django.db.models.fields.related import ForeignKey from django.db.models.fields.related_descriptors import (ForwardManyToOneDescriptor, ReverseOneToOneDescriptor) @@ -42,16 +42,7 @@ class ValuesIterable(BaseIterable): chunk_size: int chunked_fetch: bool queryset: django.db.models.query.QuerySet - def __iter__( - self - ) -> Iterator[ - Union[ - Dict[str, Optional[Union[int, str]]], - Dict[str, Union[date, Decimal, float, str]], - Dict[str, Union[date, int, str]], - Dict[str, Union[Decimal, int]], - ] - ]: ... + def __iter__(self) -> Iterator[Dict[str, Optional[Union[int, str]]]]: ... class ValuesListIterable(BaseIterable): chunk_size: int @@ -106,20 +97,13 @@ class QuerySet: def iterator(self, chunk_size: int = ...) -> Iterator[Any]: ... def aggregate( self, *args: Any, **kwargs: Any - ) -> Union[ - Dict[str, Optional[int]], - Dict[str, Union[date, time]], - Dict[str, Union[Decimal, float]], - Dict[str, timedelta], - ]: ... + ) -> Dict[str, Optional[Union[datetime, float]]]: ... def count(self) -> int: ... def get( self, *args: Any, **kwargs: Any ) -> Union[ Dict[str, Union[date, Decimal, float, str]], - Dict[str, Union[int, str]], - Tuple[Decimal], - Tuple[str, int, int], + Tuple[Union[Decimal, str]], Model, str, ]: ... @@ -131,13 +115,7 @@ class QuerySet: ) -> List[Model]: ... def get_or_create( self, - defaults: Optional[ - Union[ - Dict[str, Union[Callable, str]], - Dict[str, Union[date, str]], - Dict[str, Model], - ] - ] = ..., + defaults: Optional[Union[Dict[str, date], Dict[str, Model]]] = ..., **kwargs: Any ) -> Tuple[Model, bool]: ... def update_or_create( @@ -145,8 +123,9 @@ class QuerySet: defaults: Optional[ Union[ Dict[str, Callable], - Dict[str, Union[date, str]], + Dict[str, date], Dict[str, Model], + Dict[str, str], ] ] = ..., **kwargs: Any @@ -171,7 +150,16 @@ class QuerySet: def raw( self, raw_query: str, - params: Any = ..., + params: Optional[ + Union[ + Dict[str, str], + List[datetime], + List[Decimal], + List[str], + Set[str], + Tuple[int], + ] + ] = ..., translations: Optional[Dict[str, str]] = ..., using: None = ..., ) -> RawQuerySet: ... @@ -192,11 +180,7 @@ class QuerySet: def complex_filter( self, filter_obj: Union[ - Dict[str, Union[int, str]], - Dict[str, datetime], - Dict[str, QuerySet], - Q, - MagicMock, + Dict[str, datetime], Dict[str, QuerySet], Q, MagicMock ], ) -> QuerySet: ... def union(self, *other_qs: Any, all: bool = ...) -> QuerySet: ... @@ -212,7 +196,9 @@ class QuerySet: def distinct(self, *field_names: Any) -> QuerySet: ... def extra( self, - select: Optional[Union[Dict[str, int], Dict[str, str]]] = ..., + select: Optional[ + Union[Dict[str, int], Dict[str, str], OrderedDict] + ] = ..., where: Optional[List[str]] = ..., params: Optional[Union[List[int], List[str]]] = ..., tables: Optional[List[str]] = ..., @@ -255,7 +241,16 @@ class RawQuerySet: raw_query: str, model: Optional[Type[Model]] = ..., query: Optional[RawQuery] = ..., - params: Any = ..., + params: Optional[ + Union[ + Dict[str, str], + List[datetime], + List[Decimal], + List[str], + Set[str], + Tuple, + ] + ] = ..., translations: Optional[Dict[str, str]] = ..., using: Optional[str] = ..., hints: Optional[Dict[Any, Any]] = ..., @@ -303,11 +298,8 @@ def prefetch_related_objects( ) -> None: ... def get_prefetcher( instance: Model, through_attr: str, to_attr: str -) -> Union[ - Tuple[None, bool, bool, bool], - Tuple[GenericForeignKey, GenericForeignKey, bool, bool], - Tuple[ForwardManyToOneDescriptor, ForwardManyToOneDescriptor, bool, bool], - Tuple[ReverseOneToOneDescriptor, ReverseOneToOneDescriptor, bool, bool], +) -> Tuple[ + GenericForeignKey, Union[GenericForeignKey, property], bool, bool ]: ... def prefetch_one_level( instances: List[Model], @@ -331,7 +323,64 @@ class RelatedPopulator: remote_setter: Callable = ... def __init__( self, - klass_info: Dict[str, Any], + klass_info: Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + FieldCacheMixin, + ], + ], select: List[Tuple[Expression, Tuple[str, List[int]], Optional[str]]], db: str, ) -> None: ... @@ -340,54 +389,118 @@ class RelatedPopulator: row: Union[ List[Optional[Union[date, int, str]]], List[Union[date, Decimal, float, str]], - List[Union[datetime, time, Decimal, int, str]], - Tuple[int, Optional[str], Optional[str]], - Tuple[int, Union[int, str], Union[float, int, str]], - Tuple[int, int, None, None, int, str, str, None, None, None], - Tuple[str, int, int, int, str, int], + Tuple[Union[int, str], str, int], ], from_obj: Model, ) -> None: ... def get_related_populators( - klass_info: Union[ - Dict[str, Any], - Dict[str, Union[List[Dict[str, Any]], List[int], Type[Model]]], - Dict[ - str, - Union[ - List[ - Dict[ - str, - Union[ - Callable, List[int], Type[User], bool, ForeignKey + klass_info: Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + int + ], + Type[ + Model + ], + bool, + ForeignKey, + ], + ] + ], + List[ + int + ], + Type[ + Model + ], + bool, + ForeignKey, + ], + ] + ], + List[ + int + ], + Type[ + Model + ], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] ], - ] - ], - List[int], - Type[Model], - ], - ], - Dict[ - str, - Union[ - List[ - Dict[ - str, - Union[ - Callable, - List[int], - Type[ContentType], - bool, - ForeignKey, - ], - ] - ], - List[int], - Type[Permission], + List[int], + Type[Model], + bool, + FieldCacheMixin, + ], + ] ], + List[int], + Type[Model], + bool, + FieldCacheMixin, ], ], - select: List[Tuple[Expression, Optional[str], Optional[str]]], + select: List[Tuple[Expression, Tuple[str, List[bool]], Optional[str]]], db: str, ) -> List[RelatedPopulator]: ... diff --git a/django-stubs/db/models/query_utils.pyi b/django-stubs/db/models/query_utils.pyi index 8171a0d..0a34b85 100644 --- a/django-stubs/db/models/query_utils.pyi +++ b/django-stubs/db/models/query_utils.pyi @@ -3,11 +3,13 @@ from typing import Any, Dict, Iterator, List, Optional, Set, Tuple, Type, Union from django.db.backends.sqlite3.base import DatabaseWrapper from django.db.models.base import Model -from django.db.models.expressions import Expression, F +from django.db.models.expressions import Expression from django.db.models.fields import Field from django.db.models.fields.mixins import FieldCacheMixin from django.db.models.functions.datetime import TimezoneMixin -from django.db.models.lookups import BuiltinLookup, Lookup, Transform +from django.db.models.lookups import (FieldGetDbPrepValueMixin, + IntegerFieldFloatRounding, Lookup, + Transform) from django.db.models.options import Options from django.db.models.sql.compiler import SQLCompiler from django.db.models.sql.query import Query @@ -22,8 +24,8 @@ PathInfo = namedtuple( class InvalidQuery(Exception): ... def subclasses( - cls: Type[Union[Field, Transform]] -) -> Iterator[Type[Union[Field, Transform]]]: ... + cls: Type[RegisterLookupMixin] +) -> Iterator[Type[RegisterLookupMixin]]: ... class QueryWrapper: contains_aggregate: bool = ... @@ -36,7 +38,8 @@ class QueryWrapper: class Q(tree.Node): children: Union[ List[Dict[str, str]], - List[Union[Tuple[str, Any], django.db.models.query_utils.Q]], + List[Tuple[str, Any]], + List[django.db.models.query_utils.Q], ] connector: str negated: bool @@ -56,11 +59,7 @@ class Q(tree.Node): summarize: bool = ..., for_save: bool = ..., ) -> WhereNode: ... - def deconstruct( - self - ) -> Tuple[ - str, Tuple, Union[Dict[str, Union[bool, F]], Dict[str, str]] - ]: ... + def deconstruct(self) -> Tuple[str, Tuple, Dict[str, str]]: ... class DeferredAttribute: field_name: str = ... @@ -71,16 +70,33 @@ class DeferredAttribute: class RegisterLookupMixin: @classmethod - def get_lookups(cls) -> Dict[str, Type[Union[Lookup, Transform]]]: ... - def get_lookup(self, lookup_name: str) -> Optional[Type[Lookup]]: ... + def get_lookups( + cls + ) -> Dict[str, Type[Union[TimezoneMixin, Lookup, Transform]]]: ... + def get_lookup( + self, lookup_name: str + ) -> Optional[Type[Union[FieldGetDbPrepValueMixin, Lookup]]]: ... def get_transform(self, lookup_name: str) -> Optional[Type[Transform]]: ... @staticmethod def merge_dicts( - dicts: Union[ - List[Dict[str, Type[Union[TimezoneMixin, BuiltinLookup]]]], - List[Dict[str, Type[Union[Lookup, Transform]]]], + dicts: List[ + Dict[ + str, + Type[ + Union[ + TimezoneMixin, + FieldGetDbPrepValueMixin, + IntegerFieldFloatRounding, + Lookup, + Transform, + ] + ], + ] ] - ) -> Dict[str, Type[Union[Lookup, Transform]]]: ... + ) -> Dict[ + str, + Type[Union[TimezoneMixin, FieldGetDbPrepValueMixin, Lookup, Transform]], + ]: ... @classmethod def register_lookup( cls, @@ -113,9 +129,7 @@ def select_related_descend( ) -> bool: ... def refs_expression( lookup_parts: List[str], annotations: OrderedDict -) -> Tuple[ - Union[List[str], Tuple, Expression], Union[List[Any], List[str], Tuple] -]: ... +) -> Union[Tuple[bool, Tuple], Tuple[Expression, List[str]]]: ... def check_rel_lookup_compatibility( model: Type[Model], target_opts: Options, field: FieldCacheMixin ) -> bool: ... diff --git a/django-stubs/db/models/sql/compiler.pyi b/django-stubs/db/models/sql/compiler.pyi index b3b29e7..b3ab22e 100644 --- a/django-stubs/db/models/sql/compiler.pyi +++ b/django-stubs/db/models/sql/compiler.pyi @@ -1,16 +1,19 @@ -from datetime import date, datetime, time, timedelta +from datetime import date, datetime from decimal import Decimal from itertools import chain from typing import (Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union) from uuid import UUID +from django.contrib.contenttypes.models import ContentType from django.db.backends.sqlite3.base import DatabaseWrapper from django.db.backends.utils import CursorWrapper from django.db.models.base import Model from django.db.models.expressions import (BaseExpression, Col, Expression, - OrderBy, SQLiteNumericMixin) + OrderBy, RawSQL, SQLiteNumericMixin) from django.db.models.fields import DateTimeCheckMixin, Field +from django.db.models.fields.mixins import FieldCacheMixin +from django.db.models.fields.related import ForeignKey from django.db.models.functions.text import Lower from django.db.models.options import Options from django.db.models.sql.query import Query, RawQuery @@ -39,42 +42,23 @@ class SQLCompiler: def pre_sql_setup( self ) -> Tuple[ - Union[ - List[Tuple[OrderBy, Tuple[str, Tuple[str, str], bool]]], - List[Tuple[str, List[int]]], - List[Tuple[str, Union[List[float], List[str]]]], - ], - Union[ - List[Tuple[OrderBy, Tuple[str, List[Any], bool]]], - List[Tuple[str, List[int]]], - List[Tuple[str, Union[List[float], List[str]]]], - ], - Union[ - List[Any], - List[Tuple[str, List[int]]], - List[Tuple[str, Union[List[float], List[str]]]], + List[ + Tuple[OrderBy, Tuple[str, Union[List[Any], Tuple[str, str]]], None] ], + List[Tuple[OrderBy, Tuple[str, List[Union[int, str]], bool]]], + List[Tuple[str, List[float]]], ]: ... def get_group_by( self, - select: Union[ - List[Tuple[BaseExpression, Optional[str], Optional[str]]], - List[Tuple[SQLiteNumericMixin, Tuple[str, List[int]], str]], - ], - order_by: List[ + select: List[ Tuple[ - OrderBy, - Union[ - Tuple[str, List[Any], bool], - Tuple[str, List[Union[int, str]], bool], - Tuple[str, List[int], bool], - Tuple[str, List[str], bool], - Tuple[str, Tuple, bool], - Tuple[str, Tuple[str, str], bool], - ], + Union[BaseExpression, SQLiteNumericMixin], + Tuple[str, List[float]], + Optional[str], ] ], - ) -> List[Tuple[str, Union[List[float], List[int], List[str]]]]: ... + order_by: List[Tuple[OrderBy, Tuple[str, List[Union[int, str]], bool]]], + ) -> List[Tuple[str, List[float]]]: ... def collapse_group_by( self, expressions: List[Expression], @@ -83,59 +67,54 @@ class SQLCompiler: def get_select( self ) -> Tuple[ - Optional[Dict[str, int]], - Union[Dict[Any, Any], Dict[str, int]], - Union[Dict[Any, Any], Dict[str, int]], - ]: ... - def get_order_by( - self - ) -> List[ - Tuple[ - OrderBy, - Union[ - Tuple[str, List[Any], bool], - Tuple[str, List[Union[int, str]], bool], - Tuple[str, List[int], bool], - Tuple[str, List[str], bool], - Tuple[str, Tuple, bool], - ], - ] - ]: ... - def get_extra_select( - self, - order_by: List[ + List[ Tuple[ - OrderBy, + Union[Expression, SQLiteNumericMixin], + Tuple[str, List[Union[int, str]]], + Optional[str], + ] + ], + Optional[ + Dict[ + str, Union[ - Tuple[str, List[Any], bool], - Tuple[str, List[Union[int, str]], bool], - Tuple[str, List[int], bool], - Tuple[str, List[str], bool], - Tuple[str, Tuple, bool], + List[ + Dict[ + str, + Union[ + Callable, + List[int], + Type[ContentType], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], ], ] ], - select: Union[ - List[Tuple[Expression, Optional[str], Optional[str]]], - List[Tuple[SQLiteNumericMixin, Tuple[str, List[int]], str]], + Dict[str, int], + ]: ... + def get_order_by( + self + ) -> List[Tuple[OrderBy, Tuple[str, List[Any], bool]]]: ... + def get_extra_select( + self, + order_by: List[Tuple[OrderBy, Tuple[str, List[Any], bool]]], + select: List[ + Tuple[ + Union[Expression, SQLiteNumericMixin], + Tuple[str, List[float]], + Optional[str], + ] ], ) -> List[Tuple[OrderBy, Tuple[str, List[Any]], None]]: ... def quote_name_unless_alias(self, name: str) -> str: ... def compile( self, node: Any, select_format: Any = ... - ) -> Tuple[ - str, - Union[ - List[Optional[int]], - List[Union[date, int]], - List[Union[date, str]], - List[Union[Decimal, int]], - List[Union[int, memoryview]], - List[Union[int, str]], - List[float], - Tuple, - ], - ]: ... + ) -> Tuple[str, Union[List[Optional[int]], Tuple[int, int]]]: ... def get_combinator_sql( self, combinator: str, all: bool ) -> Tuple[List[str], Union[List[int], List[str]]]: ... @@ -156,12 +135,7 @@ class SQLCompiler: alias: Optional[str] = ..., default_order: str = ..., already_seen: Optional[ - Union[ - Set[ - Tuple[None, Tuple[Tuple[str, str]], Tuple[Tuple[str, str]]] - ], - Set[Tuple[Tuple[Tuple[str, str]], Tuple[Tuple[str, str]]]], - ] + Set[Tuple[Optional[Tuple[Tuple[str, str]]], Tuple[Tuple[str, str]]]] ] = ..., ) -> List[Tuple[OrderBy, bool]]: ... def get_from_clause(self) -> Tuple[List[str], List[Union[int, str]]]: ... @@ -175,14 +149,70 @@ class SQLCompiler: Union[Dict[str, Dict[str, Dict[str, Dict[Any, Any]]]], bool] ] = ..., restricted: Optional[bool] = ..., - ) -> List[Dict[str, Any]]: ... + ) -> List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[ + Dict[ + str, + Union[ + Callable, + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + ForeignKey, + ], + ] + ], + List[int], + Type[Model], + bool, + FieldCacheMixin, + ], + ] + ]: ... def get_select_for_update_of_arguments(self): ... def deferred_to_columns(self) -> Dict[Type[Model], Set[str]]: ... def get_converters( - self, - expressions: Union[ - List[Optional[Expression]], List[SQLiteNumericMixin] - ], + self, expressions: Union[List[RawSQL], List[SQLiteNumericMixin]] ) -> Dict[ int, Tuple[List[Callable], Union[Expression, SQLiteNumericMixin]] ]: ... @@ -194,27 +224,15 @@ class SQLCompiler: ], ) -> Iterator[ Union[ - List[Optional[Union[bool, datetime, str, UUID]]], - List[Optional[Union[bytes, date, int, str]]], - List[Optional[Union[bytes, time, int, str]]], - List[Optional[Union[bytes, timedelta, int, str]]], - List[Optional[Union[bytes, Decimal, int, str]]], - List[Optional[Union[bytes, float, str]]], - List[Optional[Union[bytes, int, str, UUID]]], - List[Optional[Union[date, time, int, str]]], + List[Optional[Union[bytes, datetime, int, str]]], List[Optional[Union[date, Decimal, float, str]]], - List[Union[date, time, timedelta, int, str]], - List[Union[datetime, time, Decimal, int, str]], - List[Union[timedelta, Decimal, int, str]], - List[Union[float, str, UUID]], + List[Optional[Union[datetime, float, str, UUID]]], ] ]: ... def results_iter( self, results: Optional[ - Union[ - Iterator[Any], List[List[Tuple[Union[date, float, int, str]]]] - ] + Union[Iterator[Any], List[List[Tuple[Union[int, str]]]]] ] = ..., tuple_expected: bool = ..., chunked_fetch: bool = ..., @@ -235,16 +253,11 @@ class SQLCompiler: class SQLInsertCompiler(SQLCompiler): return_id: bool = ... def field_as_sql( - self, - field: Optional[Field], - val: Optional[Union[Lower, float, memoryview, str]], - ) -> Tuple[ - str, - Union[List[None], List[float], List[int], List[memoryview], List[str]], - ]: ... + self, field: Optional[Field], val: Optional[Union[Lower, float, str]] + ) -> Tuple[str, Union[List[int], List[str]]]: ... def prepare_value( self, field: Field, value: Any - ) -> Optional[Union[Lower, float, memoryview, str]]: ... + ) -> Optional[Union[Lower, float, str]]: ... def pre_save_val(self, field: Field, obj: Model) -> Any: ... def assemble_as_sql( self, @@ -252,64 +265,10 @@ class SQLInsertCompiler(SQLCompiler): List[None], List[DateTimeCheckMixin], List[Field], ImmutableList ], value_rows: Union[ - List[ - Union[ - List[Optional[Union[Lower, int]]], - List[Optional[Union[int, memoryview, str]]], - ] - ], - List[ - Union[ - List[Optional[Union[float, memoryview, str]]], - List[Optional[Union[int, memoryview, str]]], - ] - ], + List[List[Optional[Union[Lower, int]]]], List[List[Union[int, str]]] ], - ) -> Tuple[ - Union[ - List[List[Optional[Union[float, str]]]], - List[List[Optional[Union[int, str]]]], - List[List[Union[int, memoryview]]], - Tuple[Tuple[str]], - ], - Union[ - List[List[Optional[Union[float, str]]]], - List[List[Optional[Union[int, str]]]], - List[ - Union[ - List[Optional[Union[float, memoryview, str]]], - List[Optional[Union[int, memoryview, str]]], - ] - ], - ], - ]: ... - def as_sql( - self - ) -> List[ - Tuple[ - str, - Union[ - List[Any], - List[None], - List[Optional[Union[bool, str]]], - List[Optional[Union[float, str]]], - List[Optional[Union[int, memoryview, str]]], - List[Optional[Union[int, str]]], - List[Optional[bool]], - List[Optional[int]], - List[Optional[str]], - List[Union[bool, str]], - List[Union[float, str]], - List[Union[int, str]], - List[bool], - List[float], - List[int], - List[memoryview], - List[str], - Tuple, - ], - ] - ]: ... + ) -> Tuple[Tuple[Tuple[str]], List[List[Optional[Union[int, str]]]]]: ... + def as_sql(self) -> List[Tuple[str, Tuple[Union[float, str]]]]: ... def execute_sql(self, return_id: Optional[bool] = ...) -> Any: ... class SQLDeleteCompiler(SQLCompiler): @@ -329,4 +288,4 @@ def cursor_iter( sentinel: List[Any], col_count: Optional[int], itersize: int, -) -> Iterator[List[Tuple[Any]]]: ... +) -> Iterator[List[Tuple[Union[date, int]]]]: ... diff --git a/django-stubs/db/models/sql/datastructures.pyi b/django-stubs/db/models/sql/datastructures.pyi index 48b71f6..3e399ee 100644 --- a/django-stubs/db/models/sql/datastructures.pyi +++ b/django-stubs/db/models/sql/datastructures.pyi @@ -42,7 +42,9 @@ class Join: def as_sql( self, compiler: SQLCompiler, connection: DatabaseWrapper ) -> Tuple[str, List[Union[int, str]]]: ... - def relabeled_clone(self, change_map: Dict[str, str]) -> Join: ... + def relabeled_clone( + self, change_map: Union[Dict[str, str], OrderedDict] + ) -> Join: ... def equals( self, other: Union[BaseTable, Join], with_filtered_relation: bool ) -> bool: ... diff --git a/django-stubs/db/models/sql/query.pyi b/django-stubs/db/models/sql/query.pyi index fb1e601..ba1a9d7 100644 --- a/django-stubs/db/models/sql/query.pyi +++ b/django-stubs/db/models/sql/query.pyi @@ -1,5 +1,5 @@ from collections import OrderedDict, namedtuple -from datetime import date, time, timedelta +from datetime import datetime from decimal import Decimal from typing import (Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union) @@ -14,9 +14,10 @@ from django.db.models.fields.mixins import FieldCacheMixin from django.db.models.fields.related_lookups import MultiColSource from django.db.models.fields.reverse_related import (ForeignObjectRel, ManyToOneRel) -from django.db.models.lookups import (FieldGetDbPrepValueMixin, Lookup, - Transform) +from django.db.models.lookups import (FieldGetDbPrepValueMixin, + IntegerLessThan, Lookup, Transform) from django.db.models.options import Options +from django.db.models.query import QuerySet from django.db.models.query_utils import FilteredRelation, PathInfo, Q from django.db.models.sql.compiler import SQLCompiler from django.db.models.sql.datastructures import BaseTable, Join @@ -43,7 +44,21 @@ class RawQuery: cursor: Optional[django.db.backends.utils.CursorWrapper] = ... extra_select: Dict[Any, Any] = ... annotation_select: Dict[Any, Any] = ... - def __init__(self, sql: str, using: str, params: Any = ...) -> None: ... + def __init__( + self, + sql: str, + using: str, + params: Optional[ + Union[ + Dict[str, str], + List[datetime], + List[Decimal], + List[str], + Set[str], + Tuple[int], + ] + ] = ..., + ) -> None: ... def chain(self, using: str) -> RawQuery: ... def clone(self, using: str) -> RawQuery: ... def get_columns(self) -> List[str]: ... @@ -54,21 +69,15 @@ class RawQuery: class Query: base_table: str related_ids: None - related_updates: Union[ - Dict[ - Type[django.db.models.base.Model], - List[Tuple[django.db.models.fields.CharField, None, str]], - ], - Dict[ - Type[django.db.models.base.Model], - List[Tuple[django.db.models.fields.IntegerField, None, int]], - ], + related_updates: Dict[ + Type[django.db.models.base.Model], + List[Tuple[django.db.models.fields.Field, None, Union[int, str]]], ] values: List[ Tuple[ django.db.models.fields.Field, - Union[django.db.models.aggregates.Max, int, str], - Union[django.db.models.aggregates.Max, int, str], + Optional[Type[django.db.models.base.Model]], + django.db.models.aggregates.Max, ] ] alias_prefix: str = ... @@ -118,7 +127,7 @@ class Query: extra_select_mask: Optional[Set[str]] = ... extra_tables: Tuple = ... extra_order_by: Union[List[str], Tuple] = ... - deferred_loading: Tuple[bool, bool] = ... + deferred_loading: Tuple[Union[Set[str], frozenset], bool] = ... explain_query: bool = ... explain_format: Optional[str] = ... explain_options: Dict[str, int] = ... @@ -153,22 +162,19 @@ class Query: def get_meta(self) -> Options: ... def clone(self) -> Query: ... def chain(self, klass: Optional[Type[Query]] = ...) -> Query: ... - def relabeled_clone(self, change_map: Dict[Any, Any]) -> Query: ... + def relabeled_clone( + self, change_map: Union[Dict[Any, Any], OrderedDict] + ) -> Query: ... def rewrite_cols( self, annotation: Union[Expression, FieldGetDbPrepValueMixin, WhereNode], col_cnt: int, - ) -> Tuple[int, int]: ... + ) -> Tuple[Union[Expression, IntegerLessThan], int]: ... def get_aggregation( self, using: str, added_aggregate_names: Union[Dict[str, SQLiteNumericMixin], List[str]], - ) -> Union[ - Dict[str, Optional[int]], - Dict[str, Union[date, time]], - Dict[str, Union[Decimal, float]], - Dict[str, timedelta], - ]: ... + ) -> Dict[str, Optional[Union[datetime, Decimal, float]]]: ... def get_count(self, using: str) -> int: ... def has_filters(self) -> WhereNode: ... def has_results(self, using: str) -> bool: ... @@ -190,7 +196,9 @@ class Query: def promote_joins(self, aliases: Set[str]) -> None: ... def demote_joins(self, aliases: Set[str]) -> None: ... def reset_refcounts(self, to_counts: Dict[str, int]) -> None: ... - def change_aliases(self, change_map: Dict[Any, Any]) -> None: ... + def change_aliases( + self, change_map: Union[Dict[Any, Any], OrderedDict] + ) -> None: ... def bump_prefix(self, outer_query: Query) -> None: ... def get_initial_alias(self) -> str: ... def count_active_tables(self) -> int: ... @@ -222,8 +230,7 @@ class Query: def solve_lookup_type( self, lookup: str ) -> Union[ - Tuple[List[str], List[str], bool], - Tuple[List[str], Tuple, Union[Expression, SQLiteNumericMixin]], + Tuple[List[str], List[str], bool], Tuple[List[str], Tuple, Expression] ]: ... def check_query_object_type( self, @@ -232,26 +239,31 @@ class Query: field: FieldCacheMixin, ) -> None: ... def check_related_objects( - self, field: Union[Field, ForeignObjectRel], value: Any, opts: Options + self, + field: Union[Field, reverse_related.ForeignObjectRel], + value: Any, + opts: Options, ) -> None: ... def build_lookup( self, lookups: List[str], - lhs: Union[Expression, TextField, related_lookups.MultiColSource], + lhs: Union[Expression, TextField, MultiColSource], rhs: Any, ) -> Lookup: ... def try_transform(self, lhs: Expression, name: str) -> Transform: ... def build_filter( self, - filter_expr: Union[Dict[str, str], Tuple[str, Any]], + filter_expr: Union[Dict[str, str], Tuple[str, Tuple[int, int]]], branch_negated: bool = ..., current_negated: bool = ..., can_reuse: Optional[Set[str]] = ..., allow_joins: bool = ..., split_subq: bool = ..., reuse_with_filtered_relation: bool = ..., - ) -> Tuple[WhereNode, Union[List[Any], Set[str], Tuple]]: ... - def add_filter(self, filter_clause: Tuple[str, Any]) -> None: ... + ) -> Tuple[WhereNode, List[Any]]: ... + def add_filter( + self, filter_clause: Tuple[str, Union[List[int], List[str]]] + ) -> None: ... def add_q(self, q_object: Q) -> None: ... def build_filtered_relation_q( self, @@ -269,11 +281,11 @@ class Query: opts: Options, allow_many: bool = ..., fail_on_missing: bool = ..., - ) -> Union[ - Tuple[ - List[PathInfo], Tuple[Field], List[str], Union[List[Any], List[str]] - ], - Tuple[List[PathInfo], Field, Tuple[Field], List[str]], + ) -> Tuple[ + List[PathInfo], + Union[Field, reverse_related.ForeignObjectRel], + Tuple[Field], + List[str], ]: ... def setup_joins( self, @@ -296,7 +308,7 @@ class Query: ) -> Expression: ... def split_exclude( self, - filter_expr: Tuple[str, Any], + filter_expr: Tuple[str, Union[QuerySet, int]], can_reuse: Set[str], names_with_path: List[Tuple[str, List[PathInfo]]], ) -> Tuple[WhereNode, Tuple]: ... @@ -325,7 +337,7 @@ class Query: def add_select_related(self, fields: Tuple[str]) -> None: ... def add_extra( self, - select: Optional[Union[Dict[str, int], Dict[str, str]]], + select: Optional[Union[Dict[str, int], Dict[str, str], OrderedDict]], select_params: Optional[Union[List[int], List[str], Tuple[int]]], where: Optional[List[str]], params: Optional[List[str]], @@ -340,7 +352,7 @@ class Query: self, target: Dict[Type[Model], Set[str]], model: Type[Model], - fields: Union[Set[Field], Set[ManyToOneRel]], + fields: Union[Set[Field], Set[reverse_related.ManyToOneRel]], ) -> None: ... def set_annotation_mask( self, names: Optional[Union[List[str], Set[str], Tuple]] @@ -349,9 +361,9 @@ class Query: def set_extra_mask(self, names: Union[List[str], Tuple]) -> None: ... def set_values(self, fields: Union[List[str], Tuple]) -> None: ... @property - def annotation_select(self) -> Dict[Any, Any]: ... + def annotation_select(self) -> Union[Dict[Any, Any], OrderedDict]: ... @property - def extra_select(self) -> Dict[Any, Any]: ... + def extra_select(self) -> Union[Dict[Any, Any], OrderedDict]: ... def trim_start( self, names_with_path: List[Tuple[str, List[PathInfo]]] ) -> Tuple[str, bool]: ... diff --git a/django-stubs/db/models/sql/subqueries.pyi b/django-stubs/db/models/sql/subqueries.pyi index a6e0974..99c1b46 100644 --- a/django-stubs/db/models/sql/subqueries.pyi +++ b/django-stubs/db/models/sql/subqueries.pyi @@ -1,9 +1,7 @@ -from datetime import datetime from typing import Any, Dict, List, Optional, Tuple, Type, Union -from uuid import UUID from django.db.models.base import Model -from django.db.models.expressions import Combinable +from django.db.models.expressions import Case from django.db.models.fields import DateTimeCheckMixin, Field from django.db.models.query import QuerySet from django.db.models.sql.query import Query @@ -51,7 +49,10 @@ class DeleteQuery(Query): values_select: Tuple where_class: Type[django.db.models.sql.where.WhereNode] compiler: str = ... - alias_map: Dict[str, django.db.models.sql.datastructures.BaseTable] = ... + alias_map: Union[ + Dict[str, django.db.models.sql.datastructures.BaseTable], + collections.OrderedDict, + ] = ... where: django.db.models.sql.where.WhereNode = ... def do_query(self, table: str, where: WhereNode, using: str) -> int: ... def delete_batch( @@ -87,15 +88,9 @@ class UpdateQuery(Query): model: Type[django.db.models.base.Model] order_by: Tuple related_ids: Optional[List[int]] - related_updates: Union[ - Dict[ - Type[django.db.models.base.Model], - List[Tuple[django.db.models.fields.CharField, None, str]], - ], - Dict[ - Type[django.db.models.base.Model], - List[Tuple[django.db.models.fields.IntegerField, None, int]], - ], + related_updates: Dict[ + Type[django.db.models.base.Model], + List[Tuple[django.db.models.fields.Field, None, Union[int, str]]], ] select: Tuple select_for_update: bool @@ -108,7 +103,13 @@ class UpdateQuery(Query): subquery: bool table_map: Dict[str, List[str]] used_aliases: Set[str] - values: List[Tuple[django.db.models.fields.Field, Any, Any]] + values: List[ + Tuple[ + django.db.models.fields.Field, + Optional[Type[django.db.models.base.Model]], + Union[django.db.models.expressions.Case, uuid.UUID], + ] + ] values_select: Tuple where_class: Type[django.db.models.sql.where.WhereNode] compiler: str = ... @@ -116,24 +117,11 @@ class UpdateQuery(Query): def clone(self) -> UpdateQuery: ... where: django.db.models.sql.where.WhereNode = ... def update_batch( - self, - pk_list: List[int], - values: Union[Dict[str, None], Dict[str, int]], - using: str, - ) -> None: ... - def add_update_values( - self, - values: Union[ - Dict[str, None], - Dict[str, Union[bool, str]], - Dict[str, Union[datetime, str]], - Dict[str, Union[Model, int]], - Dict[str, Combinable], - Dict[str, UUID], - ], + self, pk_list: List[int], values: Dict[str, Optional[int]], using: str ) -> None: ... + def add_update_values(self, values: Dict[str, Any]) -> None: ... def add_update_fields( - self, values_seq: List[Tuple[Field, Any, Any]] + self, values_seq: List[Tuple[Field, Optional[Type[Model]], Case]] ) -> None: ... def add_related_update( self, model: Type[Model], field: Field, value: Union[int, str] diff --git a/django-stubs/db/models/sql/where.pyi b/django-stubs/db/models/sql/where.pyi index c0d1b13..365c910 100644 --- a/django-stubs/db/models/sql/where.pyi +++ b/django-stubs/db/models/sql/where.pyi @@ -1,5 +1,4 @@ -from datetime import date -from decimal import Decimal +from collections import OrderedDict from typing import Any, Dict, List, Optional, Tuple, Union from django.db import DefaultConnectionProxy @@ -28,83 +27,24 @@ class WhereNode(tree.Node): self, compiler: SQLCompiler, connection: Union[DefaultConnectionProxy, DatabaseWrapper], - ) -> Tuple[ - str, - Union[ - List[Optional[int]], - List[Union[date, str]], - List[Union[Decimal, int]], - List[Union[int, str]], - List[float], - List[memoryview], - ], - ]: ... + ) -> Tuple[str, List[Union[int, str]]]: ... def get_group_by_cols(self) -> List[Expression]: ... def get_source_expressions(self) -> List[FieldGetDbPrepValueMixin]: ... - children: Union[ - List[ - Union[ - django.db.models.lookups.BuiltinLookup, - django.db.models.sql.where.ExtraWhere, - ] - ], - List[ - Union[ - django.db.models.lookups.BuiltinLookup, - django.db.models.sql.where.WhereNode, - ] - ], - List[ - Union[ - django.db.models.lookups.FieldGetDbPrepValueMixin, - django.db.models.lookups.IsNull, - ] - ], - List[ - Union[ - django.db.models.lookups.FieldGetDbPrepValueMixin, - django.db.models.query_utils.QueryWrapper, - ] - ], - List[ - Union[ - django.db.models.lookups.FieldGetDbPrepValueMixin, - django.db.models.sql.where.NothingNode, - ] - ], - List[ - Union[ - django.db.models.lookups.FieldGetDbPrepValueMixin, - django.db.models.sql.where.WhereNode, - ] - ], - List[ - Union[ - django.db.models.lookups.Lookup, - django.db.models.sql.where.NothingNode, - ] - ], - List[ - Union[ - django.db.models.sql.where.NothingNode, - django.db.models.sql.where.WhereNode, - ] - ], - List[ - Union[ - django.db.models.sql.where.SubqueryConstraint, - django.db.models.sql.where.WhereNode, - ] - ], - List[django.db.models.fields.related_lookups.RelatedLookupMixin], + children: List[ + Union[ + django.db.models.lookups.BuiltinLookup, + django.db.models.sql.where.WhereNode, + ] ] = ... def set_source_expressions( self, children: List[FieldGetDbPrepValueMixin] ) -> None: ... - def relabel_aliases(self, change_map: Dict[Optional[str], str]) -> None: ... + def relabel_aliases( + self, change_map: Union[Dict[Optional[str], str], OrderedDict] + ) -> None: ... def clone(self) -> WhereNode: ... def relabeled_clone( - self, change_map: Dict[Optional[str], str] + self, change_map: Union[Dict[Optional[str], str], OrderedDict] ) -> WhereNode: ... def contains_aggregate(self) -> bool: ... def contains_over_clause(self) -> bool: ... diff --git a/django-stubs/db/utils.pyi b/django-stubs/db/utils.pyi index 6583510..4ee43b8 100644 --- a/django-stubs/db/utils.pyi +++ b/django-stubs/db/utils.pyi @@ -33,22 +33,20 @@ def load_backend(backend_name: str) -> Any: ... class ConnectionDoesNotExist(Exception): ... class ConnectionHandler: - databases: Union[ - Dict[ - str, Dict[str, Optional[Union[Dict[str, Optional[bool]], int, str]]] - ], - Dict[ - str, Dict[str, Optional[Union[Dict[str, Optional[str]], int, str]]] - ], + databases: Dict[ + str, Dict[str, Optional[Union[Dict[str, Optional[bool]], int, str]]] ] def __init__( self, databases: Dict[str, Dict[str, Union[Dict[str, str], str]]] = ... ) -> None: ... def databases( self - ) -> Union[ - Dict[str, Dict[str, Union[Dict[str, bool], str]]], - Dict[str, Dict[str, Union[Dict[str, str], str]]], + ) -> Dict[ + str, + Union[ + Dict[str, Union[Dict[str, bool], str]], + Dict[str, Union[Dict[str, str], str]], + ], ]: ... def ensure_defaults(self, alias: str) -> None: ... def prepare_test_settings(self, alias: str) -> None: ... diff --git a/django-stubs/dispatch/dispatcher.pyi b/django-stubs/dispatch/dispatcher.pyi index f28ae7d..d202f33 100644 --- a/django-stubs/dispatch/dispatcher.pyi +++ b/django-stubs/dispatch/dispatcher.pyi @@ -32,7 +32,7 @@ class Signal: def has_listeners(self, sender: Any = ...) -> bool: ... def send( self, sender: Any, **named: Any - ) -> Union[List[Tuple[None, None]], List[Tuple[str, str]]]: ... + ) -> List[Tuple[Callable, Optional[str]]]: ... def send_robust( self, sender: SimpleTestCase, **named: Any ) -> List[Tuple[Callable, Union[ValueError, str]]]: ... diff --git a/django-stubs/forms/fields.pyi b/django-stubs/forms/fields.pyi index cfe4b2b..6b119b9 100644 --- a/django-stubs/forms/fields.pyi +++ b/django-stubs/forms/fields.pyi @@ -9,7 +9,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile from django.db.models.fields.files import FieldFile from django.forms.boundfield import BoundField from django.forms.forms import BaseForm -from django.forms.widgets import Input, Select, Widget +from django.forms.widgets import Input, Widget class Field: @@ -44,37 +44,33 @@ class Field: label_suffix: Optional[Any] = ... ) -> None: ... def prepare_value(self, value: Any) -> Any: ... - def to_python(self, value: Any) -> Any: ... + def to_python( + self, + value: Optional[Union[List[None], List[str], datetime, float, str]], + ) -> Optional[Union[List[None], List[str], datetime, float, str]]: ... def validate(self, value: Any) -> None: ... def run_validators(self, value: Any) -> None: ... def clean(self, value: Any) -> Any: ... def bound_data(self, data: Any, initial: Any) -> Any: ... def widget_attrs(self, widget: Widget) -> Dict[Any, Any]: ... - def has_changed(self, initial: Any, data: Optional[str]) -> bool: ... + def has_changed( + self, + initial: Optional[Union[datetime, Decimal, float, str]], + data: Optional[str], + ) -> bool: ... def get_bound_field( self, form: BaseForm, field_name: str ) -> BoundField: ... def __deepcopy__( self, - memo: Union[ - Dict[ - int, - Union[ - List[Tuple[str, str]], - List[Union[List[Tuple[str, str]], Field, Widget]], - OrderedDict, - Field, - Widget, - ], - ], - Dict[ - int, - Union[ - List[Union[List[Any], ChoiceField, Select]], - OrderedDict, - ChoiceField, - Select, - ], + memo: Dict[ + int, + Union[ + List[Tuple[Union[int, str], str]], + List[Widget], + OrderedDict, + Field, + Widget, ], ], ) -> Field: ... @@ -142,7 +138,7 @@ class IntegerField(Field): ) -> Optional[int]: ... def widget_attrs( self, widget: Widget - ) -> Union[Dict[str, Decimal], Dict[str, float], Dict[str, int]]: ... + ) -> Dict[str, Union[Decimal, float]]: ... class FloatField(IntegerField): disabled: bool @@ -163,9 +159,7 @@ class FloatField(IntegerField): self, value: Optional[Union[float, str]] ) -> Optional[float]: ... def validate(self, value: Optional[float]) -> None: ... - def widget_attrs( - self, widget: Input - ) -> Union[Dict[str, Union[float, str]], Dict[str, Union[int, str]]]: ... + def widget_attrs(self, widget: Input) -> Dict[str, Union[float, str]]: ... class DecimalField(IntegerField): decimal_places: Optional[int] @@ -204,14 +198,14 @@ class DecimalField(IntegerField): def validate(self, value: Optional[Decimal]) -> None: ... def widget_attrs( self, widget: Widget - ) -> Union[Dict[str, Union[Decimal, str]], Dict[str, Union[int, str]]]: ... + ) -> Dict[str, Union[Decimal, int, str]]: ... class BaseTemporalField(Field): input_formats: Any = ... def __init__( self, *, input_formats: Optional[Any] = ..., **kwargs: Any ) -> None: ... - def to_python(self, value: str) -> Union[date, time]: ... + def to_python(self, value: str) -> datetime: ... def strptime(self, value: Any, format: Any) -> None: ... class DateField(BaseTemporalField): @@ -479,8 +473,8 @@ class ChoiceField(Field): memo: Dict[ int, Union[ - List[Tuple[str, str]], - List[Union[List[Tuple[str, str]], Field, Widget]], + List[Tuple[Union[int, str], str]], + List[Widget], OrderedDict, Field, Widget, @@ -500,7 +494,7 @@ class TypedChoiceField(ChoiceField): localize: bool required: bool show_hidden_initial: bool - coerce: Union[Callable, Type[Union[float, int, str]]] = ... + coerce: Union[Callable, Type[Union[bool, float, str]]] = ... empty_value: Optional[str] = ... def __init__( self, *, coerce: Any = ..., empty_value: str = ..., **kwargs: Any @@ -542,12 +536,12 @@ class TypedMultipleChoiceField(MultipleChoiceField): localize: bool required: bool show_hidden_initial: bool - coerce: Union[Callable, Type[Union[float, int]]] = ... + coerce: Union[Callable, Type[float]] = ... empty_value: Optional[List[Any]] = ... def __init__(self, *, coerce: Any = ..., **kwargs: Any) -> None: ... def clean( self, value: List[str] - ) -> Optional[Union[List[Decimal], List[float], List[int]]]: ... + ) -> Optional[Union[List[bool], List[Decimal], List[float]]]: ... def validate(self, value: List[str]) -> None: ... class ComboField(Field): @@ -584,41 +578,22 @@ class MultiValueField(Field): ) -> None: ... def __deepcopy__( self, - memo: Union[ - Dict[ - int, - Union[ - List[Tuple[str, str]], - List[Union[List[Tuple[str, str]], Widget]], - OrderedDict, - Field, - Widget, - ], - ], - Dict[ - int, - Union[List[Union[Field, Widget]], OrderedDict, Field, Widget], - ], + memo: Dict[ + int, Union[List[Tuple[str, str]], OrderedDict, Field, Widget] ], ) -> MultiValueField: ... def validate(self, value: Union[datetime, str]) -> None: ... def clean( self, value: Optional[ - Union[ - List[None], - List[Union[List[str], str]], - List[Union[date, time]], - datetime, - str, - ] + Union[List[None], List[datetime], List[str], datetime, str] ], ) -> Optional[Union[datetime, str]]: ... def compress(self, data_list: Any) -> None: ... def has_changed( self, initial: Optional[Union[List[None], List[str], datetime, str]], - data: Union[List[None], List[Union[List[str], str]]], + data: Union[List[None], List[str]], ) -> bool: ... class FilePathField(ChoiceField): @@ -669,10 +644,7 @@ class SplitDateTimeField(MultiValueField): **kwargs: Any ) -> None: ... def compress( - self, - data_list: Union[ - List[Optional[date]], List[Optional[time]], List[Union[date, time]] - ], + self, data_list: List[Optional[datetime]] ) -> Optional[datetime]: ... class GenericIPAddressField(CharField): diff --git a/django-stubs/forms/forms.pyi b/django-stubs/forms/forms.pyi index 187af08..4a5fd59 100644 --- a/django-stubs/forms/forms.pyi +++ b/django-stubs/forms/forms.pyi @@ -1,18 +1,16 @@ from collections import OrderedDict -from datetime import date, datetime, time -from decimal import Decimal +from datetime import date, datetime from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, Union from django.core.exceptions import ValidationError from django.core.files.uploadedfile import SimpleUploadedFile -from django.db.models.base import Model -from django.db.models.fields.files import FieldFile from django.db.models.query import QuerySet from django.forms.boundfield import BoundField from django.forms.fields import Field -from django.forms.models import ModelForm from django.forms.utils import ErrorDict, ErrorList from django.forms.widgets import Media, MediaDefiningClass +from django.http.request import QueryDict +from django.utils.datastructures import MultiValueDict from django.utils.safestring import SafeText @@ -22,7 +20,7 @@ class DeclarativeFieldsMetaclass(MediaDefiningClass): name: str, bases: Tuple[Type[BaseForm]], attrs: OrderedDict, - ) -> Type[Union[Form, ModelForm]]: ... + ) -> Type[BaseForm]: ... @classmethod def __prepare__( metacls: Any, name: str, bases: Tuple[Type[BaseForm]], **kwds: Any @@ -47,22 +45,18 @@ class BaseForm: self, data: Optional[ Union[ - Dict[str, Optional[Union[List[int], datetime, int, str]]], + Dict[str, Union[List[int], int, str]], Dict[str, Union[List[str], str]], - Dict[str, Union[datetime, Decimal, int, str]], + QueryDict, ] ] = ..., - files: Optional[Dict[str, SimpleUploadedFile]] = ..., + files: Optional[ + Union[Dict[str, SimpleUploadedFile], MultiValueDict] + ] = ..., auto_id: Optional[Union[bool, str]] = ..., prefix: Optional[str] = ..., initial: Optional[ - Union[ - Dict[str, List[int]], - Dict[str, Optional[Union[List[Model], date, int, str]]], - Dict[str, Union[List[Model], Model, QuerySet]], - Dict[str, Union[List[str], str]], - Dict[str, Union[FieldFile, int, str]], - ] + Union[Dict[str, List[int]], Dict[str, date], Dict[str, str]] ] = ..., error_class: Type[ErrorList] = ..., label_suffix: None = ..., @@ -91,12 +85,8 @@ class BaseForm: def full_clean(self) -> None: ... def clean( self - ) -> Union[ - Dict[str, Optional[Union[int, str]]], - Dict[str, Union[date, time, Decimal, float]], - Dict[str, Union[date, str]], - Dict[str, SimpleUploadedFile], - Dict[str, QuerySet], + ) -> Dict[ + str, Optional[Union[datetime, SimpleUploadedFile, QuerySet, str]] ]: ... def has_changed(self) -> bool: ... def changed_data(self) -> List[str]: ... diff --git a/django-stubs/forms/formsets.pyi b/django-stubs/forms/formsets.pyi index 2cc742c..277c45d 100644 --- a/django-stubs/forms/formsets.pyi +++ b/django-stubs/forms/formsets.pyi @@ -6,7 +6,9 @@ from django.forms import Form class ManagementForm(Form): auto_id: Union[bool, str] cleaned_data: Dict[str, Optional[int]] - data: Dict[str, Union[List[int], int, str]] + data: Union[ + Dict[str, Union[List[int], int, str]], django.http.request.QueryDict + ] empty_permitted: bool error_class: Type[django.forms.utils.ErrorList] fields: collections.OrderedDict diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index 48ba941..62c4c65 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -8,10 +8,8 @@ from uuid import UUID from django.contrib.auth.forms import UserChangeForm, UserCreationForm from django.contrib.flatpages.forms import FlatpageForm -from django.core.files.base import File from django.core.files.uploadedfile import SimpleUploadedFile from django.db.models.base import Model -from django.db.models.fields.files import FieldFile from django.db.models.manager import Manager from django.db.models.query import QuerySet from django.db.models.query_utils import Q @@ -19,7 +17,9 @@ from django.forms.fields import CharField, ChoiceField, Field from django.forms.forms import BaseForm, DeclarativeFieldsMetaclass from django.forms.formsets import BaseFormSet from django.forms.utils import ErrorList -from django.forms.widgets import Widget +from django.forms.widgets import Input, Widget +from django.http.request import QueryDict +from django.utils.datastructures import MultiValueDict ALL_FIELDS: str @@ -27,17 +27,12 @@ def model_to_dict( instance: Model, fields: Optional[Union[List[Union[Callable, str]], Tuple[str]]] = ..., exclude: Optional[Union[List[Union[Callable, str]], Tuple[str]]] = ..., -) -> Union[ - Dict[str, Optional[Union[List[Model], date, int, str]]], - Dict[str, Optional[FieldFile]], - Dict[str, Union[FieldFile, int, str]], - Dict[str, float], -]: ... +) -> Dict[str, Optional[Union[bool, date, float]]]: ... def fields_for_model( model: Type[Model], fields: Optional[Union[List[Union[Callable, str]], Tuple]] = ..., exclude: Optional[Union[List[Union[Callable, str]], Tuple]] = ..., - widgets: Optional[Dict[str, Union[Type[Widget], Widget]]] = ..., + widgets: Optional[Union[Dict[str, Type[Input]], Dict[str, Widget]]] = ..., formfield_callback: Optional[Union[Callable, str]] = ..., localized_fields: Optional[Union[Tuple[str], str]] = ..., labels: Optional[Dict[str, str]] = ..., @@ -53,11 +48,9 @@ class ModelFormOptions: fields: Optional[Union[List[Union[Callable, str]], Tuple, str]] = ... exclude: Optional[Union[List[Union[Callable, str]], Tuple, str]] = ... widgets: Optional[ - Dict[ - str, - Union[ - Type[django.forms.widgets.Widget], django.forms.widgets.Widget - ], + Union[ + Dict[str, Type[django.forms.widgets.Input]], + Dict[str, django.forms.widgets.Widget], ] ] = ... localized_fields: Optional[Union[Tuple[str], str]] = ... @@ -97,19 +90,15 @@ class BaseModelForm(BaseForm): Dict[str, Optional[Union[List[int], datetime, int, str]]], Dict[str, Union[List[str], str]], Dict[str, Union[datetime, Decimal, int, str]], + QueryDict, ] ] = ..., - files: Optional[Dict[str, SimpleUploadedFile]] = ..., + files: Optional[ + Union[Dict[str, SimpleUploadedFile], MultiValueDict] + ] = ..., auto_id: Union[bool, str] = ..., prefix: None = ..., - initial: Optional[ - Union[ - Dict[str, List[int]], - Dict[str, Union[List[Model], Model, QuerySet]], - Dict[str, Union[List[str], str]], - Dict[str, int], - ] - ] = ..., + initial: Optional[Union[Dict[str, List[int]], Dict[str, int]]] = ..., error_class: Type[ErrorList] = ..., label_suffix: None = ..., empty_permitted: bool = ..., @@ -117,15 +106,7 @@ class BaseModelForm(BaseForm): use_required_attribute: None = ..., renderer: Any = ..., ) -> None: ... - def clean( - self - ) -> Union[ - Dict[str, Optional[Union[bool, datetime, QuerySet, str]]], - Dict[str, Optional[Union[date, Model, QuerySet, str]]], - Dict[str, Optional[Union[Model, int, str]]], - Dict[str, Union[datetime, Decimal, int, str]], - Dict[str, Union[File, str]], - ]: ... + def clean(self) -> Dict[str, Any]: ... def validate_unique(self) -> None: ... save_m2m: Any = ... def save(self, commit: bool = ...) -> Model: ... @@ -282,7 +263,7 @@ class ModelChoiceIterator: field: django.forms.models.ModelChoiceField = ... queryset: Optional[django.db.models.query.QuerySet] = ... def __init__(self, field: ModelChoiceField) -> None: ... - def __iter__(self) -> Iterator[Tuple[str, str]]: ... + def __iter__(self) -> Iterator[Tuple[Union[int, str], str]]: ... def __len__(self) -> int: ... def __bool__(self) -> bool: ... def choice(self, obj: Model) -> Tuple[int, str]: ... @@ -321,9 +302,7 @@ class ModelChoiceField(ChoiceField): ) -> None: ... def get_limit_choices_to( self - ) -> Optional[ - Union[Dict[str, Union[int, str]], Dict[str, datetime], Q, MagicMock] - ]: ... + ) -> Optional[Union[Dict[str, datetime], Q, MagicMock]]: ... def __deepcopy__( self, memo: Dict[ @@ -359,87 +338,19 @@ class ModelMultipleChoiceField(ModelChoiceField): default_error_messages: Any = ... def __init__(self, queryset: QuerySet, **kwargs: Any) -> None: ... def to_python( - self, - value: Union[ - List[str], - Tuple[ - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - ], - ], + self, value: Union[List[str], Tuple[int, ...]] ) -> List[Model]: ... def clean( self, value: Optional[ Union[ - List[Dict[str, str]], - List[List[str]], - List[Union[int, str]], - List[Model], - Tuple, - str, + List[Dict[str, str]], List[List[str]], List[Model], Tuple, str ] ], ) -> QuerySet: ... def prepare_value( self, value: Any - ) -> Optional[ - Union[ - List[Dict[str, str]], - List[List[str]], - List[Union[int, str]], - int, - str, - ] - ]: ... + ) -> Optional[Union[List[Dict[str, str]], List[List[str]], int, str]]: ... def has_changed( self, initial: Optional[Union[List[Model], QuerySet, str]], diff --git a/django-stubs/forms/renderers.pyi b/django-stubs/forms/renderers.pyi index fb155fe..7f989c1 100644 --- a/django-stubs/forms/renderers.pyi +++ b/django-stubs/forms/renderers.pyi @@ -1,6 +1,5 @@ from datetime import time -from decimal import Decimal -from typing import Any, Dict, List, Optional, Set, Tuple, Union +from typing import Any, Dict, List, Optional, Tuple, Union from django.template.backends.base import BaseEngine from django.template.backends.django import Template @@ -15,68 +14,18 @@ class BaseRenderer: def render( self, template_name: str, - context: Union[ - Dict[ - str, + context: Dict[ + str, + Union[ Dict[ str, Optional[ Union[ - Dict[str, Union[bool, float, str]], + Dict[str, bool], List[ - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Optional[ - Union[ - Dict[ - str, - Union[ - bool, - str, - ], - ], - bool, - str, - ] - ], - ] - ], - bool, - str, - ] - ], - ], - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[Any, Any], - bool, - str, - ], - ] - ], - int, - ] - ], - bool, - str, - ], - ], + Dict[ + str, + Optional[Union[Dict[str, str], bool, str]], ] ], bool, @@ -84,153 +33,55 @@ class BaseRenderer: ] ], ], - ], - Dict[ - str, - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[Decimal, int, str]], - List[ - Dict[ - str, - Optional[Union[Dict[str, str], bool, str]], - ] - ], - int, - str, - ] - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Tuple[ - List[ - Dict[str, Union[Dict[Any, Any], bool, str]] - ], - int, - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Union[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Dict[ - str, - Union[ - Dict[Any, Any], bool, str - ], - ] - ], - bool, - str, - ], - ], - Dict[ - str, - Union[ - Dict[str, bool], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], - bool, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ] - ], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Union[ - Tuple[ - None, - List[ - Dict[ - str, - Union[Dict[Any, Any], bool, str], - ] - ], - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[Dict[str, bool], bool, str], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, Dict[ str, Union[ Dict[str, Union[bool, str]], + List[ + Dict[ + str, + Union[ + Dict[str, Union[bool, str]], + List[ + Tuple[ + None, + List[ + Dict[ + str, + Union[ + Dict[str, bool], + bool, + str, + ], + ] + ], + int, + ] + ], + List[str], + bool, + str, + ], + ] + ], + List[str], + bool, + str, + ], + ], + Dict[ + str, + Union[ + Dict[str, Union[int, str]], List[ Tuple[ - None, + Optional[str], List[ Dict[ str, Union[ Dict[str, Union[bool, str]], + time, int, str, ], @@ -240,178 +91,10 @@ class BaseRenderer: ] ], List[str], - bool, + int, str, ], ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Union[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ], - ] - ], - bool, - str, - ], - ], - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], - bool, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ] - ], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Union[ - Tuple[ - None, - List[ - Dict[ - str, - Union[Dict[str, bool], bool, str], - ] - ], - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[Dict[Any, Any], bool, str], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[int, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[Dict[Any, Any], time, int, str], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[int, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], Set[str], int, str - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, bool], - List[ - Tuple[ - List[ - Dict[str, Union[Dict[str, bool], bool, str]] - ], - int, - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, Dict[ str, Union[ @@ -423,316 +106,6 @@ class BaseRenderer: ], ], ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Tuple[ - None, - List[ - Dict[str, Union[Dict[str, str], int, str]] - ], - int, - ] - ], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Union[ - Tuple[ - None, - List[ - Dict[ - str, - Union[Dict[str, str], bool, str], - ] - ], - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[Any, Any], - List[ - Dict[ - str, - Optional[ - Union[Dict[Any, Any], bool, str] - ], - ] - ], - bool, - str, - ] - ], - ], - List[Dict[str, str]], - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ] - ], - ] - ], - bool, - str, - ] - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[str, str], - List[ - Dict[ - str, - Optional[ - Union[Dict[str, str], bool, str] - ], - ] - ], - bool, - str, - ] - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[str, Optional[Union[Dict[str, str], bool, str]]], - List[Dict[str, str]], - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], - bool, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ] - ], - List[str], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[Dict[str, Union[Dict[str, str], bool, str]]], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], bool, str - ], - ] - ], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, str], - List[Dict[str, Union[Dict[str, str], bool, str]]], - List[str], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, str], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[Dict[str, str], bool, str], - ] - ], - int, - ] - ], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, str], - List[ - Union[ - Tuple[ - List[ - Dict[ - str, - Union[ - Dict[str, str], bool, str - ], - ] - ], - int, - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - List[Dict[str, str]], - ], - ], - Dict[str, Union[bool, str]], ], request: None = ..., ) -> str: ... diff --git a/django-stubs/forms/utils.pyi b/django-stubs/forms/utils.pyi index c9a16a8..0131077 100644 --- a/django-stubs/forms/utils.pyi +++ b/django-stubs/forms/utils.pyi @@ -7,9 +7,7 @@ from django.utils.safestring import SafeText def pretty_name(name: str) -> str: ... -def flatatt( - attrs: Union[Dict[str, None], Dict[str, Union[bool, str]]] -) -> SafeText: ... +def flatatt(attrs: Dict[str, Optional[str]]) -> SafeText: ... class ErrorDict(dict): def as_data(self) -> Dict[str, List[ValidationError]]: ... @@ -25,7 +23,9 @@ class ErrorList(UserList, list): error_class: str = ... def __init__( self, - initlist: Optional[Union[List[ValidationError], List[str]]] = ..., + initlist: Optional[ + Union[List[ValidationError], List[str], ErrorList] + ] = ..., error_class: Optional[str] = ..., ) -> None: ... def as_data(self) -> List[ValidationError]: ... @@ -36,7 +36,7 @@ class ErrorList(UserList, list): def as_ul(self) -> str: ... def as_text(self) -> str: ... def __contains__(self, item: str) -> bool: ... - def __eq__(self, other: List[str]) -> bool: ... + def __eq__(self, other: Union[List[str], ErrorList]) -> bool: ... def __getitem__(self, i: Union[int, str]) -> str: ... def __reduce_ex__( self, *args: Any, **kwargs: Any diff --git a/django-stubs/forms/widgets.pyi b/django-stubs/forms/widgets.pyi index 5ff76b3..84616a8 100644 --- a/django-stubs/forms/widgets.pyi +++ b/django-stubs/forms/widgets.pyi @@ -5,20 +5,15 @@ from itertools import chain from typing import (Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union) -from django.contrib.admin.filters import SimpleListFilter -from django.contrib.admin.options import (InlineModelAdmin, StackedInline, - TabularInline) -from django.contrib.contenttypes.admin import GenericInlineModelAdminChecks -from django.contrib.contenttypes.forms import BaseGenericInlineFormSet +from django.contrib.admin.options import BaseModelAdmin from django.core.files.base import File from django.core.files.uploadedfile import SimpleUploadedFile -from django.core.paginator import Paginator -from django.db.models.base import Model -from django.db.models.fields import CharField, IntegerField from django.db.models.fields.files import FieldFile from django.forms.fields import Field -from django.forms.models import ModelForm +from django.forms.forms import BaseForm from django.forms.renderers import EngineMixin +from django.http.request import QueryDict +from django.utils.datastructures import MultiValueDict from django.utils.safestring import SafeText @@ -45,108 +40,8 @@ class Media: class MediaDefiningClass(type): def __new__( - mcs: Type[MediaDefiningClass], - name: str, - bases: Tuple, - attrs: Union[ - Dict[str, Any], - Dict[ - str, - Optional[Union[List[str], Tuple[str, str, str, str], int, str]], - ], - Dict[ - str, - Union[ - Callable, - Dict[str, Tuple[str]], - List[Type[Union[StackedInline, TabularInline]]], - List[str], - str, - ], - ], - Dict[str, Union[Callable, Dict[str, Tuple[str]], Type[Model], str]], - Dict[ - str, - Union[ - Callable, - List[Type[InlineModelAdmin]], - List[str], - Tuple[str, str, str], - str, - ], - ], - Dict[str, Union[Callable, List[Type[TabularInline]], bool, str]], - Dict[str, Union[Callable, List[str], Type[Model], str]], - Dict[ - str, - Union[ - Callable, - Tuple[str], - Type[Union[Model, ModelForm]], - int, - str, - ], - ], - Dict[ - str, - Union[ - Callable, - Type[ - Union[ - GenericInlineModelAdminChecks, - BaseGenericInlineFormSet, - ] - ], - str, - ], - ], - Dict[str, Union[Callable, property, str]], - Dict[ - str, - Union[ - Dict[Type[CharField], Dict[str, bool]], - Dict[str, List[str]], - List[Type[Union[StackedInline, TabularInline]]], - Tuple[ - Tuple[ - None, - Dict[ - str, - Tuple[ - Tuple[str, str], Tuple[str, str, str, str] - ], - ], - ] - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[Type[IntegerField], Dict[str, Type[NumberInput]]], - Type[Model], - str, - ], - ], - Dict[ - str, - Union[ - Dict[str, Tuple[str]], - Tuple[ - Tuple[str, Dict[str, Tuple[str]]], - Tuple[str, Dict[str, Tuple[str]]], - ], - Type[Union[Model, ModelForm]], - str, - ], - ], - Dict[str, Union[List[Callable], str]], - Dict[str, Union[List[Type[SimpleListFilter]], str]], - Dict[str, Union[List[str], Tuple[str], Type[ModelForm], str]], - Dict[str, Union[Type[Paginator], str]], - ], - ) -> Type[Any]: ... + mcs: Type[MediaDefiningClass], name: str, bases: Tuple, attrs: Any + ) -> Type[Union[BaseModelAdmin, BaseForm, Widget]]: ... class Widget: needs_multipart_form: bool = ... @@ -157,32 +52,11 @@ class Widget: def __init__( self, attrs: Optional[ - Union[Dict[str, None], Dict[str, Union[int, str]], Dict[str, float]] + Union[Dict[str, None], Dict[str, bool], Dict[str, float]] ] = ..., ) -> None: ... def __deepcopy__( - self, - memo: Union[ - Dict[ - int, - Union[ - Dict[Any, Any], - List[Union[List[Any], Field, Widget]], - Field, - Widget, - ], - ], - Dict[ - int, - Union[ - List[Tuple[str, str]], - List[Union[List[Tuple[str, str]], Field, Widget]], - OrderedDict, - Field, - Widget, - ], - ], - ], + self, memo: Dict[int, Union[Dict[Any, Any], List[Any]]] ) -> Widget: ... @property def is_hidden(self) -> bool: ... @@ -195,33 +69,15 @@ class Widget: name: str, value: Any, attrs: Optional[Dict[str, Union[bool, str]]], - ) -> Union[ - Dict[ - str, - Dict[ - str, - Optional[ - Union[Dict[str, Union[bool, Decimal, str]], bool, str] - ], - ], + ) -> Dict[ + str, + Union[ + Dict[str, Optional[Union[Dict[str, None], bool, str]]], + Dict[str, Optional[Union[Dict[str, bool], bool, str]]], + Dict[str, Union[Dict[str, Union[int, str]], List[str], bool, str]], + Dict[str, Union[Dict[str, str], List[int], bool, str]], + Dict[str, Union[Dict[str, str], bool, FieldFile, str]], ], - Dict[ - str, - Dict[ - str, - Optional[Union[Dict[str, Union[float, int, str]], bool, str]], - ], - ], - Dict[str, Dict[str, Union[Dict[str, None], List[str], bool, str]]], - Dict[ - str, - Dict[str, Union[Dict[str, Union[bool, str]], List[int], bool, str]], - ], - Dict[ - str, - Dict[str, Union[Dict[str, Union[bool, str]], List[str], bool, str]], - ], - Dict[str, Dict[str, Union[Dict[str, str], bool, FieldFile, str]]], ]: ... def render( self, @@ -232,25 +88,23 @@ class Widget: ) -> SafeText: ... def build_attrs( self, - base_attrs: Union[ - Dict[str, Union[Decimal, str]], - Dict[str, Union[float, str]], - Dict[str, Union[int, str]], - ], + base_attrs: Dict[str, Union[float, str]], extra_attrs: Optional[Dict[str, Union[bool, str]]] = ..., - ) -> Union[ - Dict[str, Union[bool, float, str]], Dict[str, Union[Decimal, int, str]] - ]: ... + ) -> Dict[str, Union[Decimal, float, str]]: ... def value_from_datadict( - self, data: dict, files: Dict[str, SimpleUploadedFile], name: str + self, + data: dict, + files: Union[Dict[str, SimpleUploadedFile], MultiValueDict], + name: str, ) -> Any: ... def value_omitted_from_data( self, data: Union[ Dict[str, Optional[Union[List[int], date, int, str]]], Dict[str, Union[datetime, Decimal, int, str]], + QueryDict, ], - files: Dict[str, SimpleUploadedFile], + files: Union[Dict[str, SimpleUploadedFile], MultiValueDict], name: str, ) -> bool: ... def id_for_label(self, id_: str) -> str: ... @@ -263,7 +117,12 @@ class Input(Widget): def __init__( self, attrs: Optional[ - Union[Dict[str, None], Dict[str, Union[int, str]], Dict[str, float]] + Union[ + Dict[str, None], + Dict[str, bool], + Dict[str, float], + Dict[str, str], + ] ] = ..., ) -> None: ... def get_context( @@ -271,41 +130,25 @@ class Input(Widget): name: str, value: Any, attrs: Optional[Dict[str, Union[bool, str]]], - ) -> Union[ - Dict[ - str, - Dict[ - str, - Optional[ - Union[Dict[str, Union[bool, Decimal, str]], bool, str] - ], - ], + ) -> Dict[ + str, + Union[ + Dict[str, Optional[Union[Dict[str, Union[int, str]], bool, str]]], + Dict[str, Union[Dict[str, str], List[int], bool, str]], + Dict[str, Union[Dict[str, str], List[str], bool, str]], + Dict[str, Union[Dict[str, str], bool, FieldFile, str]], ], - Dict[ - str, - Dict[ - str, - Optional[Union[Dict[str, Union[float, int, str]], bool, str]], - ], - ], - Dict[str, Dict[str, Union[Dict[str, str], List[int], bool, str]]], - Dict[str, Dict[str, Union[Dict[str, str], List[str], bool, str]]], - Dict[str, Dict[str, Union[Dict[str, str], bool, FieldFile, str]]], ]: ... class TextInput(Input): - attrs: Union[Dict[str, None], Dict[str, Union[int, str]]] + attrs: Dict[str, Optional[bool]] is_localized: bool is_required: bool input_type: str = ... template_name: str = ... class NumberInput(Input): - attrs: Union[ - Dict[str, Union[decimal.Decimal, str]], - Dict[str, Union[float, str]], - Dict[str, int], - ] + attrs: Dict[str, Union[float, str]] is_required: bool input_type: str = ... template_name: str = ... @@ -323,7 +166,7 @@ class URLInput(Input): template_name: str = ... class PasswordInput(Input): - attrs: Union[Dict[str, bool], Dict[str, str]] + attrs: Dict[str, Union[bool, str]] is_required: bool input_type: str = ... template_name: str = ... @@ -359,22 +202,9 @@ class MultipleHiddenInput(HiddenInput): name: str, value: Optional[Union[List[int], List[str]]], attrs: Optional[Dict[str, str]], - ) -> Union[ - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[Dict[str, Union[Dict[Any, Any], bool, str]]], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, + ) -> Dict[ + str, + Union[ Dict[ str, Union[ @@ -385,9 +215,6 @@ class MultipleHiddenInput(HiddenInput): str, ], ], - ], - Dict[ - str, Dict[ str, Union[ @@ -403,126 +230,17 @@ class MultipleHiddenInput(HiddenInput): def value_from_datadict( self, data: Union[ - Dict[str, List[str]], - Dict[ - str, - Tuple[ - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - ], - ], + Dict[str, List[str]], Dict[str, Tuple[int, ...]], MultiValueDict ], files: Dict[Any, Any], name: str, - ) -> Union[ - List[str], - Tuple[ - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - ], - ]: ... + ) -> Union[List[str], Tuple[int, ...]]: ... def format_value( self, value: Optional[Union[List[int], List[str]]] ) -> Union[List[int], List[str]]: ... class FileInput(Input): - attrs: Union[Dict[str, bool], Dict[str, str]] + attrs: Dict[str, Union[bool, str]] is_required: bool input_type: str = ... needs_multipart_form: bool = ... @@ -530,14 +248,16 @@ class FileInput(Input): def format_value(self, value: Optional[str]) -> None: ... def value_from_datadict( self, - data: Union[Dict[str, None], Dict[str, bool], Dict[str, str]], - files: Union[Dict[str, SimpleUploadedFile], Dict[str, str]], + data: Union[ + Dict[str, None], Dict[str, bool], Dict[str, str], QueryDict + ], + files: Dict[str, Union[SimpleUploadedFile, str]], name: str, ) -> Optional[Union[SimpleUploadedFile, str]]: ... def value_omitted_from_data( self, data: Dict[str, str], - files: Union[Dict[str, SimpleUploadedFile], Dict[str, str]], + files: Dict[str, Union[SimpleUploadedFile, str]], name: str, ) -> bool: ... @@ -557,8 +277,10 @@ class ClearableFileInput(FileInput): def get_context(self, name: Any, value: Any, attrs: Any): ... def value_from_datadict( self, - data: Union[Dict[str, None], Dict[str, bool], Dict[str, str]], - files: Union[Dict[str, SimpleUploadedFile], Dict[str, str]], + data: Union[ + Dict[str, None], Dict[str, bool], Dict[str, str], QueryDict + ], + files: Dict[str, Union[SimpleUploadedFile, str]], name: str, ) -> Any: ... def use_required_attribute( @@ -567,12 +289,12 @@ class ClearableFileInput(FileInput): def value_omitted_from_data( self, data: Dict[str, str], - files: Union[Dict[str, SimpleUploadedFile], Dict[str, str]], + files: Dict[str, Union[SimpleUploadedFile, str]], name: str, ) -> bool: ... class Textarea(Widget): - attrs: Union[Dict[str, int], Dict[str, str]] + attrs: Dict[str, Union[int, str]] is_required: bool template_name: str = ... def __init__( @@ -589,7 +311,7 @@ class DateTimeBaseInput(TextInput): format: Optional[str] = ..., ) -> None: ... def format_value( - self, value: Optional[Union[date, time, str]] + self, value: Optional[Union[datetime, str]] ) -> Optional[str]: ... class DateInput(DateTimeBaseInput): @@ -643,14 +365,18 @@ class CheckboxInput(Input): ]: ... def value_from_datadict( self, - data: Dict[str, Optional[Union[List[int], datetime, int, str]]], - files: Dict[str, SimpleUploadedFile], + data: Union[ + Dict[str, Optional[Union[List[int], datetime, int, str]]], QueryDict + ], + files: Union[Dict[str, SimpleUploadedFile], MultiValueDict], name: str, ) -> bool: ... def value_omitted_from_data( self, - data: Dict[str, Optional[Union[List[int], datetime, int, str]]], - files: Dict[Any, Any], + data: Union[ + Dict[str, Optional[Union[List[int], datetime, int, str]]], QueryDict + ], + files: Union[Dict[Any, Any], MultiValueDict], name: str, ) -> bool: ... @@ -669,32 +395,12 @@ class ChoiceWidget(Widget): choices: Union[ Iterator[Any], List[List[Union[int, str]]], - List[ - Union[ - Tuple[ - Union[List[Tuple[str, str]], str], - Union[List[Tuple[str, str]], str], - ], - Tuple[int, int], - ] - ], + List[Tuple[Union[time, int], int]], List[int], Tuple, ] = ..., ) -> None: ... - def __deepcopy__( - self, - memo: Dict[ - int, - Union[ - List[Tuple[str, str]], - List[Union[List[Tuple[str, str]], Field, Widget]], - OrderedDict, - Field, - Widget, - ], - ], - ) -> ChoiceWidget: ... + def __deepcopy__(self, memo: Dict[int, List[Any]]) -> ChoiceWidget: ... def subwidgets( self, name: str, @@ -712,15 +418,12 @@ class ChoiceWidget(Widget): name: str, value: List[str], attrs: Optional[Dict[str, Union[bool, str]]] = ..., - ) -> Union[ - List[ - Tuple[ - None, - List[Dict[str, Union[Dict[str, Union[bool, str]], int, str]]], - int, - ] - ], - List[Tuple[int, int, int]], + ) -> List[ + Tuple[ + Optional[str], + List[Dict[str, Union[Dict[str, Union[bool, str]], time, int, str]]], + int, + ] ]: ... def create_option( self, @@ -731,305 +434,61 @@ class ChoiceWidget(Widget): index: int, subindex: Optional[int] = ..., attrs: Optional[Dict[str, Union[bool, str]]] = ..., - ) -> Union[ - Dict[str, Union[Dict[Any, Any], bool, time, str]], - Dict[str, Union[Dict[str, Union[bool, str]], Set[str], int, str]], + ) -> Dict[ + str, + Union[ + Dict[str, Union[bool, str]], + Dict[str, bool], + Set[str], + time, + int, + str, + ], ]: ... def get_context( self, name: str, - value: Any, + value: Optional[Union[List[int], List[str], Tuple[str, str], int, str]], attrs: Optional[Dict[str, Union[bool, str]]], - ) -> Union[ + ) -> Dict[ + str, Dict[ str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Tuple[ - List[Dict[str, Union[Dict[Any, Any], bool, str]]], - int, - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Tuple[ + Union[ + Dict[str, Union[bool, str]], + List[ + Tuple[ + Optional[str], + Union[ List[Dict[str, Union[Dict[str, bool], bool, str]]], - int, - int, - ] - ], - List[str], - bool, - str, + List[Dict[str, Union[Dict[str, str], bool, str]]], + ], + int, + ] ], - ], - ], - Dict[ - str, - Dict[ + List[str], + bool, str, - Union[ - Dict[Any, Any], - List[ - Union[ - Tuple[ - None, - List[ - Dict[str, Union[Dict[Any, Any], bool, str]] - ], - int, - ], - Tuple[ - str, - List[ - Dict[str, Union[Dict[str, bool], bool, str]] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[str, Union[Dict[Any, Any], time, int, str]] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], int, str - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[Dict[str, bool], Set[str], int, str], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Union[ - Tuple[ - None, - List[ - Dict[str, Union[Dict[str, bool], bool, str]] - ], - int, - ], - Tuple[ - str, - List[ - Dict[str, Union[Dict[Any, Any], bool, str]] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Tuple[ - None, - List[Dict[str, Union[Dict[str, str], int, str]]], - int, - ] - ], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Union[ - Tuple[ - List[ - Dict[str, Union[Dict[str, str], bool, str]] - ], - int, - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Union[ - Tuple[ - None, - List[ - Dict[str, Union[Dict[str, str], bool, str]] - ], - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], ], ], ]: ... def id_for_label(self, id_: str, index: str = ...) -> str: ... def value_from_datadict( - self, data: dict, files: Dict[Any, Any], name: str + self, + data: dict, + files: Union[Dict[Any, Any], MultiValueDict], + name: str, ) -> Optional[Union[List[str], int, str]]: ... - def format_value(self, value: Any) -> List[str]: ... + def format_value( + self, + value: Optional[Union[List[int], List[str], Tuple[str, str], int, str]], + ) -> List[str]: ... class Select(ChoiceWidget): attrs: Dict[str, Union[bool, str]] choices: Union[ List[List[Union[int, str]]], - List[ - Union[ - Tuple[ - Union[ - List[Tuple[str, str]], - Tuple[Tuple[str, str], Tuple[str, str]], - str, - ], - Union[ - List[Tuple[str, str]], - Tuple[Tuple[str, str], Tuple[str, str]], - str, - ], - ], - Tuple[int, Union[int, str]], - ] - ], + List[Tuple[datetime.time, Union[int, str]]], django.forms.fields.CallableChoiceIterator, django.forms.models.ModelChoiceIterator, ] @@ -1045,148 +504,26 @@ class Select(ChoiceWidget): name: str, value: Optional[Union[List[int], List[str], int, str]], attrs: Optional[Dict[str, Union[bool, str]]], - ) -> Union[ + ) -> Dict[ + str, Dict[ str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Tuple[ - List[Dict[str, Union[Dict[Any, Any], bool, str]]], - int, - int, - ] - ], - List[str], - bool, - str, + Union[ + Dict[str, Union[bool, str]], + List[ + Tuple[ + Optional[str], + List[ + Dict[ + str, Union[Dict[str, bool], Set[str], int, str] + ] + ], + int, + ] ], - ], - ], - Dict[ - str, - Dict[ + List[str], + bool, str, - Union[ - Dict[Any, Any], - List[ - Union[ - Tuple[ - None, - List[ - Dict[str, Union[Dict[Any, Any], bool, str]] - ], - int, - ], - Tuple[ - str, - List[ - Dict[str, Union[Dict[str, bool], bool, str]] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[str, Union[Dict[Any, Any], time, int, str]] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[Dict[str, bool], Set[str], int, str], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Union[ - Tuple[ - None, - List[ - Dict[str, Union[Dict[str, bool], bool, str]] - ], - int, - ], - Tuple[ - str, - List[ - Dict[str, Union[Dict[Any, Any], bool, str]] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, bool], - List[ - Tuple[ - List[Dict[str, Union[Dict[str, bool], bool, str]]], - int, - int, - ] - ], - List[str], - bool, - str, - ], ], ], ]: ... @@ -1198,8 +535,8 @@ class NullBooleanSelect(Select): def format_value(self, value: Optional[Union[bool, str]]) -> str: ... def value_from_datadict( self, - data: Dict[str, Union[bool, str]], - files: Dict[Any, Any], + data: Union[Dict[str, Union[bool, str]], QueryDict], + files: Union[Dict[Any, Any], MultiValueDict], name: str, ) -> Optional[bool]: ... @@ -1214,65 +551,12 @@ class SelectMultiple(Select): def value_from_datadict( self, data: Union[ - Dict[str, Optional[Union[List[int], datetime, int, str]]], - Dict[ - str, - Tuple[ - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - ], - ], - Dict[str, Union[List[str], str]], + Dict[str, List[int]], + Dict[str, Tuple[int, ...]], + Dict[str, str], + QueryDict, ], - files: Dict[Any, Any], + files: Union[Dict[Any, Any], MultiValueDict], name: str, ) -> Optional[Union[List[int], List[str], str]]: ... def value_omitted_from_data( @@ -1282,7 +566,12 @@ class SelectMultiple(Select): class RadioSelect(ChoiceWidget): attrs: Dict[str, str] choices: Union[ - List[Tuple[str, Union[Tuple[Tuple[str, str], Tuple[str, str]], str]]], + List[ + Tuple[ + datetime.time, + Union[Tuple[Tuple[str, str], Tuple[str, str]], str], + ] + ], List[int], django.forms.models.ModelChoiceIterator, ] @@ -1296,7 +585,7 @@ class CheckboxSelectMultiple(ChoiceWidget): choices: Union[ List[ Tuple[ - Union[Tuple[Tuple[str, str], Tuple[str, str]], str], + datetime.time, Union[Tuple[Tuple[str, str], Tuple[str, str]], str], ] ], @@ -1319,7 +608,9 @@ class MultiWidget(Widget): widgets: List[django.forms.widgets.Widget] = ... def __init__( self, - widgets: Union[List[Union[Type[TextInput], RadioSelect]], Tuple[Input]], + widgets: Union[ + List[Type[DateTimeBaseInput]], Tuple[Union[Type[TextInput], Input]] + ], attrs: Optional[Dict[str, str]] = ..., ) -> None: ... @property @@ -1327,36 +618,11 @@ class MultiWidget(Widget): def get_context( self, name: str, - value: Optional[ - Union[ - List[Union[List[str], str]], - List[Union[date, time]], - datetime, - str, - ] - ], + value: Optional[Union[List[datetime], datetime, str]], attrs: Optional[Dict[str, Union[bool, str]]], - ) -> Union[ - Dict[ - str, - Dict[ - str, - Optional[ - Union[ - Dict[Any, Any], - List[ - Dict[ - str, Optional[Union[Dict[Any, Any], bool, str]] - ] - ], - bool, - str, - ] - ], - ], - ], - Dict[ - str, + ) -> Dict[ + str, + Union[ Dict[ str, Optional[ @@ -1377,95 +643,6 @@ class MultiWidget(Widget): ] ], ], - ], - Dict[ - str, - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - List[ - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Optional[ - Union[ - Dict[ - str, - Union[ - bool, str - ], - ], - bool, - str, - ] - ], - ] - ], - bool, - str, - ] - ], - ], - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[Any, Any], - bool, - str, - ], - ] - ], - int, - ] - ], - bool, - str, - ], - ], - ] - ], - bool, - str, - ] - ], - ], - ], - Dict[ - str, - Dict[ - str, - Optional[ - Union[ - Dict[str, str], - List[ - Dict[ - str, Optional[Union[Dict[str, str], bool, str]] - ] - ], - bool, - str, - ] - ], - ], - ], - Dict[ - str, Dict[ str, Union[ @@ -1500,147 +677,28 @@ class MultiWidget(Widget): ], ], ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Union[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Dict[ - str, - Union[Dict[Any, Any], bool, str], - ] - ], - bool, - str, - ], - ], - Dict[ - str, - Union[ - Dict[str, bool], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], - bool, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ] - ], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Union[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ], - ] - ], - bool, - str, - ], - ], - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], - bool, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ] - ], - bool, - str, - ], - ], - ], ]: ... def id_for_label(self, id_: str) -> str: ... def value_from_datadict( self, - data: Dict[str, Union[List[str], str]], - files: Dict[Any, Any], + data: Union[Dict[str, Union[List[str], str]], QueryDict], + files: Union[Dict[Any, Any], MultiValueDict], name: str, - ) -> Union[List[None], List[Union[List[str], str]]]: ... + ) -> Union[List[None], List[str]]: ... def value_omitted_from_data( - self, data: Dict[str, str], files: Dict[Any, Any], name: str + self, + data: Union[Dict[str, str], QueryDict], + files: Union[Dict[Any, Any], MultiValueDict], + name: str, ) -> bool: ... def decompress(self, value: Any) -> None: ... media: Any = ... def __deepcopy__( self, - memo: Union[ - Dict[ - int, - Union[ - List[Tuple[str, str]], - List[Union[List[Tuple[str, str]], Widget]], - OrderedDict, - Field, - Widget, - ], - ], - Dict[ - int, - Union[List[Union[Field, Widget]], OrderedDict, Field, Widget], + memo: Dict[ + int, + Union[ + List[Tuple[str, str]], List[Widget], OrderedDict, Field, Widget ], ], ) -> MultiWidget: ... @@ -1663,7 +721,7 @@ class SplitDateTimeWidget(MultiWidget): ) -> None: ... def decompress( self, value: Optional[Union[datetime, str]] - ) -> Union[List[None], List[Union[date, time]]]: ... + ) -> Union[List[None], List[datetime]]: ... class SplitHiddenDateTimeWidget(SplitDateTimeWidget): attrs: Dict[Any, Any] @@ -1704,7 +762,7 @@ class SelectDateWidget(Widget): def get_context(self, name: Any, value: Any, attrs: Any): ... def format_value( self, value: Optional[Union[date, str]] - ) -> Union[Dict[str, None], Dict[str, Union[int, str]]]: ... + ) -> Dict[str, None]: ... def id_for_label(self, id_: str) -> str: ... def value_from_datadict( self, data: Dict[str, str], files: Dict[Any, Any], name: str diff --git a/django-stubs/http/multipartparser.pyi b/django-stubs/http/multipartparser.pyi index 246200e..679fce1 100644 --- a/django-stubs/http/multipartparser.pyi +++ b/django-stubs/http/multipartparser.pyi @@ -61,18 +61,6 @@ class Parser: self ) -> Iterator[ Tuple[ - str, - Dict[ - str, - Tuple[ - str, - Union[ - Dict[str, Union[bytes, str]], - Dict[str, bytes], - Dict[str, str], - ], - ], - ], - LazyStream, + str, Dict[str, Tuple[str, Dict[str, Union[bytes, str]]]], LazyStream ] ]: ... diff --git a/django-stubs/http/request.pyi b/django-stubs/http/request.pyi index 4f7140e..6f321d1 100644 --- a/django-stubs/http/request.pyi +++ b/django-stubs/http/request.pyi @@ -16,8 +16,8 @@ class HttpRequest: get_host: Callable sensitive_post_parameters: str session: django.contrib.sessions.backends.db.SessionStore - GET: Dict[str, str] = ... - POST: Dict[str, str] = ... + GET: Union[Dict[str, str], django.http.request.QueryDict] = ... + POST: Union[Dict[str, str], django.http.request.QueryDict] = ... COOKIES: Dict[str, str] = ... META: Dict[str, Union[int, str]] = ... FILES: django.utils.datastructures.MultiValueDict = ... diff --git a/django-stubs/http/response.pyi b/django-stubs/http/response.pyi index 821501a..016341e 100644 --- a/django-stubs/http/response.pyi +++ b/django-stubs/http/response.pyi @@ -289,7 +289,6 @@ class JsonResponse(HttpResponse): self, data: Union[ Dict[str, Dict[str, str]], - Dict[str, Union[Dict[str, bool], List[Dict[str, str]]]], Dict[str, int], Dict[str, str], List[int], diff --git a/django-stubs/middleware/cache.pyi b/django-stubs/middleware/cache.pyi index 4830810..318c4be 100644 --- a/django-stubs/middleware/cache.pyi +++ b/django-stubs/middleware/cache.pyi @@ -9,10 +9,7 @@ class UpdateCacheMiddleware(MiddlewareMixin): cache_timeout: float = ... key_prefix: str = ... cache_alias: str = ... - cache: Union[ - django.core.cache.DefaultCacheProxy, - django.core.cache.backends.base.BaseCache, - ] = ... + cache: django.core.cache.backends.base.BaseCache = ... get_response: Optional[Callable] = ... def __init__(self, get_response: Optional[Callable] = ...) -> None: ... def process_response( @@ -22,10 +19,7 @@ class UpdateCacheMiddleware(MiddlewareMixin): class FetchFromCacheMiddleware(MiddlewareMixin): key_prefix: str = ... cache_alias: str = ... - cache: Union[ - django.core.cache.DefaultCacheProxy, - django.core.cache.backends.base.BaseCache, - ] = ... + cache: django.core.cache.backends.base.BaseCache = ... get_response: Optional[Callable] = ... def __init__(self, get_response: Optional[Callable] = ...) -> None: ... def process_request( diff --git a/django-stubs/middleware/csrf.pyi b/django-stubs/middleware/csrf.pyi index 2a1382d..c1d6eda 100644 --- a/django-stubs/middleware/csrf.pyi +++ b/django-stubs/middleware/csrf.pyi @@ -1,11 +1,7 @@ -from typing import Any, Callable, Dict, Optional, Tuple, Type, Union +from typing import Any, Callable, Dict, Optional, Tuple -from django.contrib.sitemaps import Sitemap -from django.core.exceptions import PermissionDenied, SuspiciousOperation -from django.http.multipartparser import MultiPartParserError from django.http.request import HttpRequest -from django.http.response import (Http404, HttpResponseBase, - HttpResponseForbidden) +from django.http.response import HttpResponseBase, HttpResponseForbidden from django.utils.deprecation import MiddlewareMixin logger: Any @@ -31,17 +27,7 @@ class CsrfViewMiddleware(MiddlewareMixin): request: HttpRequest, callback: Callable, callback_args: Tuple, - callback_kwargs: Union[ - Dict[str, Dict[str, Sitemap]], - Dict[str, Dict[str, str]], - Dict[str, None], - Dict[str, Union[Dict[str, Type[Sitemap]], str]], - Dict[str, Union[int, str]], - Dict[str, PermissionDenied], - Dict[str, SuspiciousOperation], - Dict[str, MultiPartParserError], - Dict[str, Http404], - ], + callback_kwargs: Dict[str, Any], ) -> Optional[HttpResponseForbidden]: ... def process_response( self, request: HttpRequest, response: HttpResponseBase diff --git a/django-stubs/shortcuts.pyi b/django-stubs/shortcuts.pyi index 71ec662..22fb2e7 100644 --- a/django-stubs/shortcuts.pyi +++ b/django-stubs/shortcuts.pyi @@ -4,7 +4,6 @@ from django.core.handlers.wsgi import WSGIRequest from django.db.models.base import Model from django.db.models.manager import Manager from django.db.models.query import QuerySet -from django.forms.forms import Form from django.http.response import HttpResponse, HttpResponseRedirect @@ -18,14 +17,7 @@ def render_to_response( def render( request: WSGIRequest, template_name: Union[List[str], str], - context: Optional[ - Union[ - Dict[str, Optional[str]], - Dict[str, Union[Manager, QuerySet]], - Dict[str, Union[Form, str]], - Dict[str, bool], - ] - ] = ..., + context: Optional[Dict[str, bool]] = ..., content_type: Optional[str] = ..., status: Optional[int] = ..., using: Optional[str] = ..., diff --git a/django-stubs/template/backends/django.pyi b/django-stubs/template/backends/django.pyi index 72b97b5..0c72452 100644 --- a/django-stubs/template/backends/django.pyi +++ b/django-stubs/template/backends/django.pyi @@ -1,24 +1,9 @@ -from datetime import datetime, time -from decimal import Decimal -from typing import (Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, - Union) -from unittest.mock import MagicMock +from typing import Any, Dict, Iterator, Optional -from django.contrib.auth.forms import AuthenticationForm -from django.contrib.auth.views import LoginView -from django.contrib.sites.requests import RequestSite -from django.core.paginator import Page, Paginator -from django.db.models.base import Model -from django.db.models.manager import Manager -from django.db.models.query import QuerySet -from django.forms.forms import BaseForm from django.http.request import HttpRequest from django.template.base import Origin, Template -from django.template.context import Context from django.template.exceptions import TemplateDoesNotExist from django.utils.safestring import SafeText -from django.views.generic.base import TemplateResponseMixin -from django.views.generic.list import ListView from .base import BaseEngine @@ -29,25 +14,7 @@ class DjangoTemplates(BaseEngine): name: str app_dirname: str = ... engine: django.template.engine.Engine = ... - def __init__( - self, - params: Union[ - Dict[str, Union[Dict[str, Dict[str, str]], List[Any], bool, str]], - Dict[ - str, - Union[ - Dict[str, List[Tuple[str, Dict[str, str]]]], - List[Any], - bool, - str, - ], - ], - Dict[str, Union[Dict[str, List[str]], List[str], bool, str]], - Dict[str, Union[Dict[str, Tuple[str]], List[str], bool, str]], - Dict[str, Union[Dict[str, bool], List[Any], bool, str]], - Dict[str, Union[Dict[str, str], List[Any], bool, str]], - ], - ) -> None: ... + def __init__(self, params: Dict[str, Any]) -> None: ... def from_string(self, template_code: str) -> Template: ... def get_template(self, template_name: str) -> Template: ... def get_templatetag_libraries( @@ -63,829 +30,7 @@ class Template: @property def origin(self) -> Origin: ... def render( - self, - context: Optional[ - Union[ - Dict[str, Any], - Dict[ - str, - Dict[ - str, - Optional[ - Union[Dict[str, Union[bool, float, str]], bool, str] - ], - ], - ], - Dict[ - str, - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[Decimal, int, str]], - List[ - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Optional[ - Union[ - Dict[ - str, - Union[ - bool, - str, - ], - ], - bool, - str, - ] - ], - ] - ], - bool, - str, - ] - ], - ], - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[ - Any, Any - ], - bool, - str, - ], - ] - ], - int, - ] - ], - bool, - str, - ], - ], - ] - ], - bool, - str, - ] - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Tuple[ - List[ - Dict[ - str, - Union[Dict[Any, Any], bool, str], - ] - ], - int, - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Union[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Dict[ - str, - Union[ - Dict[Any, Any], - bool, - str, - ], - ] - ], - bool, - str, - ], - ], - Dict[ - str, - Union[ - Dict[str, bool], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], - bool, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ] - ], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Union[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[Any, Any], bool, str - ], - ] - ], - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[str, bool], bool, str - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Union[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Union[ - Dict[ - str, - Union[bool, str], - ], - bool, - str, - ], - ] - ], - bool, - str, - ], - ], - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], - bool, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ] - ], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Union[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], bool, str - ], - ] - ], - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[Any, Any], bool, str - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[int, str]], - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], bool, str - ], - ] - ], - int, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[int, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[Any, Any], time, int, str - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[int, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], - Set[str], - int, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, bool], - List[ - Tuple[ - List[ - Dict[ - str, - Union[Dict[str, bool], bool, str], - ] - ], - int, - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[Dict[str, Union[Dict[str, str], bool, str]]], - List[int], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Tuple[ - None, - List[ - Dict[ - str, Union[Dict[str, str], int, str] - ] - ], - int, - ] - ], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Union[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, str], bool, str - ], - ] - ], - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, Optional[Union[List[Dict[str, str]], bool, ListView]] - ], - Dict[str, Optional[str]], - Dict[str, Union[Callable, int]], - Dict[ - str, - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[Any, Any], - List[ - Dict[ - str, - Optional[ - Union[Dict[Any, Any], bool, str] - ], - ] - ], - bool, - str, - ] - ], - ], - List[Dict[str, Optional[Union[datetime, Model, str]]]], - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ] - ], - ] - ], - bool, - str, - ] - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Optional[ - Union[Dict[str, str], bool, str] - ], - ] - ], - int, - str, - ] - ], - ], - TemplateResponseMixin, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Optional[ - Union[ - Dict[str, str], - List[ - Dict[ - str, - Optional[ - Union[Dict[str, str], bool, str] - ], - ] - ], - bool, - str, - ] - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[str, Optional[Union[Dict[str, str], bool, str]]], - List[Dict[str, str]], - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], - bool, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ] - ], - List[str], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Dict[str, Union[Dict[str, str], bool, str]] - ], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ], - ] - ], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - int, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, str], - List[ - Dict[str, Union[Dict[str, str], bool, str]] - ], - List[str], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, str], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, str], bool, str - ], - ] - ], - int, - ] - ], - bool, - str, - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, str], - List[ - Union[ - Tuple[ - List[ - Dict[ - str, - Union[ - Dict[str, str], - bool, - str, - ], - ] - ], - int, - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[ - str, - Union[bool, str], - ], - bool, - str, - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - List[Dict[str, str]], - ], - ], - Dict[ - str, - Union[ - List[Dict[str, str]], bool, Page, Paginator, ListView - ], - ], - Dict[str, Union[List[str], str]], - Dict[str, Union[bool, str]], - Dict[ - str, Union[AuthenticationForm, LoginView, RequestSite, str] - ], - Dict[str, Union[Model, BaseForm, TemplateResponseMixin, str]], - Dict[str, Union[Manager, QuerySet]], - Dict[str, Template], - Context, - MagicMock, - ] - ] = ..., - request: Optional[HttpRequest] = ..., + self, context: Any = ..., request: Optional[HttpRequest] = ... ) -> SafeText: ... def copy_exception( diff --git a/django-stubs/template/backends/jinja2.pyi b/django-stubs/template/backends/jinja2.pyi index 8561be5..b41e6e2 100644 --- a/django-stubs/template/backends/jinja2.pyi +++ b/django-stubs/template/backends/jinja2.pyi @@ -52,7 +52,7 @@ class Template: Dict[ str, Optional[ - Union[Dict[Any, Any], bool, str] + Union[Dict[str, str], bool, str] ], ] ], @@ -67,12 +67,36 @@ class Template: Dict[ str, Union[ - Dict[Any, Any], + Dict[str, int], + List[ + Tuple[ + Optional[str], + List[ + Dict[ + str, + Union[Dict[str, bool], bool, str], + ] + ], + int, + ] + ], + List[str], + bool, + str, + ], + ], + ], + Dict[ + str, + Dict[ + str, + Union[ + Dict[str, str], List[ Dict[ str, Union[ - Dict[Any, Any], + Dict[str, str], List[ Tuple[ None, @@ -101,215 +125,6 @@ class Template: ], ], ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Tuple[ - List[ - Dict[ - str, - Union[Dict[Any, Any], bool, str], - ] - ], - int, - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Union[ - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Dict[ - str, - Union[ - Dict[Any, Any], - bool, - str, - ], - ] - ], - bool, - str, - ], - ], - Dict[ - str, - Union[ - Dict[str, bool], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], - bool, - str, - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ] - ], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[Any, Any], - List[ - Union[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, bool], bool, str - ], - ] - ], - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[Any, Any], bool, str - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, bool], - List[ - Tuple[ - List[ - Dict[ - str, - Union[Dict[str, bool], bool, str], - ] - ], - int, - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, bool], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[Dict[str, bool], int, str], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, int], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[Any, Any], time, int, str - ], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[Dict[str, Union[Dict[str, str], bool, str]]], - List[str], - bool, - str, - ], - ], - ], Dict[ str, Dict[ @@ -318,13 +133,14 @@ class Template: Dict[str, str], List[ Tuple[ - None, + Optional[str], List[ Dict[ str, Union[ Dict[str, Union[bool, str]], - bool, + time, + int, str, ], ] @@ -338,154 +154,6 @@ class Template: ], ], ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Tuple[ - None, - List[ - Dict[ - str, - Union[Dict[str, bool], int, str], - ] - ], - int, - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Union[ - Tuple[ - List[ - Dict[ - str, - Union[ - Dict[str, str], bool, str - ], - ] - ], - int, - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Union[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[Any, Any], bool, str - ], - ] - ], - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[str, bool], bool, str - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, str], - List[ - Union[ - Tuple[ - None, - List[ - Dict[ - str, - Union[ - Dict[str, str], bool, str - ], - ] - ], - int, - ], - Tuple[ - str, - List[ - Dict[ - str, - Union[ - Dict[str, Union[bool, str]], - bool, - str, - ], - ] - ], - int, - ], - ] - ], - List[str], - bool, - str, - ], - ], - ], Dict[str, TemplateView], Dict[str, str], ] diff --git a/django-stubs/template/base.pyi b/django-stubs/template/base.pyi index f57d4bc..db9aed0 100644 --- a/django-stubs/template/base.pyi +++ b/django-stubs/template/base.pyi @@ -35,11 +35,9 @@ class TokenType(Enum): class VariableDoesNotExist(Exception): msg: str = ... - params: Union[Tuple[Dict[str, str]], Tuple[str, Any]] = ... + params: Tuple[Union[Dict[str, str], str]] = ... def __init__( - self, - msg: str, - params: Union[Tuple[Dict[str, str]], Tuple[str, Any]] = ..., + self, msg: str, params: Tuple[Union[Dict[str, str], str]] = ... ) -> None: ... class Origin: @@ -158,10 +156,14 @@ class FilterExpression: filters: List[ Tuple[ Callable, - Union[ - List[Any], - List[Tuple[bool, django.template.base.Variable]], - List[Tuple[bool, django.utils.safestring.SafeText]], + List[ + Tuple[ + bool, + Union[ + django.template.base.Variable, + django.utils.safestring.SafeText, + ], + ] ], ] ] = ... @@ -191,11 +193,7 @@ class Variable: def resolve( self, context: Union[ - Dict[str, Dict[str, Union[int, str]]], - Dict[str, Union[int, str]], - Context, - int, - str, + Dict[str, Dict[str, Union[int, str]]], Context, int, str ], ) -> Any: ... diff --git a/django-stubs/template/context.pyi b/django-stubs/template/context.pyi index 8f29455..d221922 100644 --- a/django-stubs/template/context.pyi +++ b/django-stubs/template/context.pyi @@ -1,18 +1,22 @@ from itertools import cycle -from typing import Any, Dict, Iterator, List, Optional, Union +from typing import Any, Callable, Dict, Iterator, List, Optional, Type, Union -from django.contrib.admin.templatetags.base import InclusionAdminNode -from django.core.handlers.wsgi import WSGIRequest +from django.contrib.admin.templatetags.admin_list import ResultList +from django.contrib.admin.views.main import ChangeList +from django.db.models.base import Model +from django.db.models.options import Options +from django.forms.boundfield import BoundField +from django.http.request import HttpRequest from django.template.base import Node, Origin, Template -from django.template.defaulttags import CycleNode +from django.template.defaulttags import CycleNode, IfChangedNode +from django.template.library import InclusionNode from django.template.loader_tags import BlockContext -from django.utils.functional import SimpleLazyObject class ContextPopException(Exception): ... class ContextDict(dict): - context: Any = ... + context: django.template.context.BaseContext = ... def __init__( self, context: BaseContext, *args: Any, **kwargs: Any ) -> None: ... @@ -25,26 +29,51 @@ class BaseContext: def __iter__(self) -> None: ... def push(self, *args: Any, **kwargs: Any) -> ContextDict: ... def pop(self) -> ContextDict: ... - def __setitem__(self, key: Union[str, Node], value: Any) -> None: ... - def set_upward(self, key: Any, value: Any) -> None: ... - def __getitem__(self, key: str) -> Any: ... + def __setitem__(self, key: Union[Node, str], value: Any) -> None: ... + def set_upward(self, key: str, value: Union[int, str]) -> None: ... + def __getitem__(self, key: Union[int, str]) -> Any: ... def __delitem__(self, key: Any) -> None: ... def __contains__(self, key: str) -> bool: ... def get( self, key: str, otherwise: Optional[int] = ... - ) -> Union[SimpleLazyObject, int]: ... + ) -> Optional[Union[Options, int, str]]: ... def setdefault( - self, key: str, default: List[Origin] = ... - ) -> List[Origin]: ... - def new(self, values: Any = ...) -> RequestContext: ... - def flatten(self): ... - def __eq__(self, other: Any): ... + self, + key: Union[IfChangedNode, str], + default: Optional[Union[List[Origin], int]] = ..., + ) -> Optional[Union[List[Origin], int]]: ... + def new( + self, + values: Optional[ + Union[ + Dict[ + str, + Union[ + List[Dict[str, Union[int, str]]], + List[ResultList], + List[BoundField], + ChangeList, + int, + ], + ], + Dict[str, Union[List[Dict[str, str]], ChangeList, int, str]], + Dict[str, Union[ChangeList, int, range, str]], + Context, + ] + ] = ..., + ) -> Context: ... + def flatten( + self + ) -> Dict[ + str, Optional[Union[Dict[str, Union[Type[Any], str]], int, str]] + ]: ... + def __eq__(self, other: Context) -> bool: ... class Context(BaseContext): - dicts: List + dicts: Any autoescape: bool = ... use_l10n: Optional[bool] = ... - use_tz: None = ... + use_tz: Optional[bool] = ... template_name: Optional[str] = ... render_context: django.template.context.RenderContext = ... template: Optional[django.template.base.Template] = ... @@ -52,54 +81,36 @@ class Context(BaseContext): self, dict_: Any = ..., autoescape: bool = ..., - use_l10n: None = ..., + use_l10n: Optional[bool] = ..., use_tz: None = ..., ) -> None: ... def bind_template(self, template: Template) -> Iterator[None]: ... def __copy__(self) -> Context: ... - def update(self, other_dict: Dict[str, Any]) -> ContextDict: ... + def update( + self, + other_dict: Union[ + Dict[str, Model], Dict[str, int], Dict[str, str], Context + ], + ) -> ContextDict: ... class RenderContext(BaseContext): - dicts: Union[ - List[ - Dict[ - Union[str, django.template.loader_tags.IncludeNode], - Union[bool, None, Dict[str, django.template.base.Template]], - ] - ], - List[ - Union[ - Dict[ - Union[str, django.template.loader_tags.IncludeNode], - Union[bool, None, Dict[Any, Any]], - ], - django.template.context.ContextDict, - ] - ], - List[ - Union[ - Dict[str, Union[bool, None]], - Dict[str, str], - django.template.context.ContextDict, - ] - ], - ] + dicts: List[Dict[Union[django.template.loader_tags.IncludeNode, str], str]] template: Optional[django.template.base.Template] = ... def __iter__(self) -> None: ... - def __contains__(self, key: Union[str, CycleNode]) -> bool: ... + def __contains__(self, key: Union[CycleNode, str]) -> bool: ... def get( - self, key: Union[str, InclusionAdminNode], otherwise: None = ... - ) -> Optional[Union[BlockContext, Template]]: ... + self, key: Union[InclusionNode, str], otherwise: None = ... + ) -> Optional[Union[Template, BlockContext]]: ... def __getitem__( - self, key: Union[str, CycleNode] - ) -> Union[List[Origin], BlockContext, cycle]: ... + self, key: Union[Node, str] + ) -> Optional[Union[List[Origin], BlockContext, cycle]]: ... def push_state( self, template: Template, isolated_context: bool = ... ) -> Iterator[None]: ... class RequestContext(Context): autoescape: bool - dicts: List + dicts: List[Dict[str, str]] render_context: django.template.context.RenderContext template_name: Optional[str] use_l10n: None @@ -107,17 +118,39 @@ class RequestContext(Context): request: django.http.request.HttpRequest = ... def __init__( self, - request: WSGIRequest, - dict_: None = ..., - processors: None = ..., + request: HttpRequest, + dict_: Optional[ + Dict[str, Union[Dict[str, Union[Type[Any], str]], str]] + ] = ..., + processors: Optional[List[Callable]] = ..., use_l10n: None = ..., use_tz: None = ..., autoescape: bool = ..., ) -> None: ... template: Optional[django.template.base.Template] = ... def bind_template(self, template: Template) -> Iterator[None]: ... - def new(self, values: Any = ...) -> RequestContext: ... + def new( + self, + values: Optional[ + Union[ + Dict[str, Union[Dict[str, str], List[Dict[str, str]], bool]], + Dict[str, Union[List[Any], ChangeList, int, str]], + Dict[ + str, + Union[ + List[Dict[str, Optional[Union[int, str]]]], + List[ResultList], + List[BoundField], + ChangeList, + int, + ], + ], + Dict[str, Union[ChangeList, int, range, str]], + Context, + ] + ] = ..., + ) -> RequestContext: ... def make_context( - context: Dict[str, Any], request: Optional[WSGIRequest] = ..., **kwargs: Any + context: Any, request: Optional[HttpRequest] = ..., **kwargs: Any ) -> Context: ... diff --git a/django-stubs/template/defaultfilters.pyi b/django-stubs/template/defaultfilters.pyi index 572b2ab..8b59a15 100644 --- a/django-stubs/template/defaultfilters.pyi +++ b/django-stubs/template/defaultfilters.pyi @@ -1,8 +1,7 @@ -from datetime import date, time, timedelta +from datetime import date, datetime, timedelta from decimal import Decimal from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union -from django.db.models.query import QuerySet from django.utils.safestring import SafeText from .base import Variable, VariableDoesNotExist @@ -52,7 +51,7 @@ def dictsort( value: Union[ Dict[str, int], List[Dict[str, Dict[str, Union[int, str]]]], - List[Dict[str, Union[int, str]]], + List[Dict[str, str]], List[Tuple[str, str]], List[int], int, @@ -61,7 +60,7 @@ def dictsort( arg: Union[int, str], ) -> Union[ List[Dict[str, Dict[str, Union[int, str]]]], - List[Dict[str, Union[int, str]]], + List[Dict[str, str]], List[Tuple[str, str]], str, ]: ... @@ -79,21 +78,17 @@ def dictsortreversed( def first(value: Union[List[int], List[str], str]) -> Union[int, str]: ... def join(value: Any, arg: str, autoescape: bool = ...) -> Any: ... def last(value: List[str]) -> str: ... -def length( - value: Optional[ - Union[ - List[Optional[Union[Dict[Any, Any], int, str]]], QuerySet, int, str - ] - ] -) -> int: ... -def length_is(value: Any, arg: Union[SafeText, int]) -> Union[bool, str]: ... +def length(value: Any) -> int: ... +def length_is( + value: Optional[Union[List[Callable], Tuple[str, str], int, str]], + arg: Union[SafeText, int], +) -> Union[bool, str]: ... def random(value: List[str]) -> str: ... def slice_filter(value: Any, arg: str) -> Any: ... def unordered_list( value: Union[ Iterator[Any], List[Union[List[Union[List[Union[List[str], str]], str]], str]], - List[Union[List[Union[List[str], str]], str]], ], autoescape: bool = ..., ) -> SafeText: ... @@ -103,10 +98,10 @@ def add( ) -> Union[List[int], Tuple[int, int, int, int], date, int, str]: ... def get_digit(value: Union[int, str], arg: int) -> Union[int, str]: ... def date( - value: Optional[Union[date, time, str]], arg: Optional[str] = ... + value: Optional[Union[datetime, str]], arg: Optional[str] = ... ) -> str: ... def time( - value: Optional[Union[date, time, str]], arg: Optional[str] = ... + value: Optional[Union[datetime, str]], arg: Optional[str] = ... ) -> str: ... def timesince_filter( value: Optional[date], arg: Optional[date] = ... diff --git a/django-stubs/template/defaulttags.pyi b/django-stubs/template/defaulttags.pyi index 8552d22..f6d0597 100644 --- a/django-stubs/template/defaulttags.pyi +++ b/django-stubs/template/defaulttags.pyi @@ -84,15 +84,15 @@ class ForNode(Node): token: django.template.base.Token child_nodelists: Any = ... is_reversed: bool = ... - nodelist_loop: List[str] = ... - nodelist_empty: List[str] = ... + nodelist_loop: Union[List[str], django.template.base.NodeList] = ... + nodelist_empty: Union[List[str], django.template.base.NodeList] = ... def __init__( self, loopvars: Union[List[str], str], sequence: Union[FilterExpression, str], is_reversed: bool, - nodelist_loop: List[str], - nodelist_empty: Optional[List[str]] = ..., + nodelist_loop: Union[List[str], NodeList], + nodelist_empty: Optional[Union[List[str], NodeList]] = ..., ) -> None: ... def render(self, context: Context) -> SafeText: ... @@ -108,8 +108,8 @@ class IfChangedNode(Node): def render(self, context: Context) -> str: ... class IfEqualNode(Node): - nodelist_false: List[Any] - nodelist_true: List[Any] + nodelist_false: Union[List[Any], django.template.base.NodeList] + nodelist_true: Union[List[Any], django.template.base.NodeList] origin: django.template.base.Origin token: django.template.base.Token var1: Union[django.template.base.FilterExpression, str] @@ -120,8 +120,8 @@ class IfEqualNode(Node): self, var1: Union[FilterExpression, str], var2: Union[FilterExpression, str], - nodelist_true: List[Any], - nodelist_false: List[Any], + nodelist_true: Union[List[Any], NodeList], + nodelist_false: Union[List[Any], NodeList], negate: bool, ) -> None: ... def render(self, context: Context) -> SafeText: ... @@ -130,10 +130,14 @@ class IfNode(Node): origin: django.template.base.Origin token: django.template.base.Token conditions_nodelists: List[ - Tuple[django.template.base.NodeList, django.template.base.NodeList] + Tuple[ + Optional[django.template.defaulttags.TemplateLiteral], + django.template.base.NodeList, + ] ] = ... def __init__( - self, conditions_nodelists: List[Tuple[NodeList, NodeList]] + self, + conditions_nodelists: List[Tuple[Optional[TemplateLiteral], NodeList]], ) -> None: ... def __iter__(self) -> None: ... @property @@ -166,13 +170,7 @@ class RegroupNode(Node): var_name: str, ) -> None: ... def resolve_expression( - self, - obj: Union[ - Dict[str, Union[List[str], str]], - Dict[str, Union[int, str]], - Dict[str, date], - ], - context: Context, + self, obj: Dict[str, date], context: Context ) -> Union[int, str]: ... def render(self, context: Context) -> str: ... @@ -255,15 +253,15 @@ class WidthRatioNode(Node): class WithNode(Node): origin: django.template.base.Origin token: django.template.base.Token - nodelist: List[Any] = ... - extra_context: Union[ - Dict[str, django.template.base.FilterExpression], Dict[str, str] + nodelist: Union[List[Any], django.template.base.NodeList] = ... + extra_context: Dict[ + str, Union[django.template.base.FilterExpression, str] ] = ... def __init__( self, var: Optional[str], name: Optional[str], - nodelist: List[Any], + nodelist: Union[List[Any], NodeList], extra_context: Optional[Dict[str, FilterExpression]] = ..., ) -> None: ... def render(self, context: Context) -> Any: ... diff --git a/django-stubs/template/engine.pyi b/django-stubs/template/engine.pyi index 006e357..e3b087d 100644 --- a/django-stubs/template/engine.pyi +++ b/django-stubs/template/engine.pyi @@ -1,4 +1,3 @@ -from datetime import date, time, timedelta from typing import Any, Callable, Dict, List, Optional, Tuple, Union from django.template.base import Origin, Template @@ -23,19 +22,8 @@ class Engine: debug: bool = ... loaders: Union[ List[List[Union[Dict[str, str], str]]], - List[ - Union[ - Tuple[ - str, - Union[ - Dict[str, str], - List[Tuple[str, Dict[str, str]]], - List[str], - ], - ], - str, - ] - ], + List[Tuple[str, List[str]]], + List[str], ] = ... string_if_invalid: str = ... file_charset: str = ... @@ -52,19 +40,8 @@ class Engine: loaders: Optional[ Union[ List[List[Union[Dict[str, str], str]]], - List[ - Union[ - Tuple[ - str, - Union[ - Dict[str, str], - List[Tuple[str, Dict[str, str]]], - List[str], - ], - ], - str, - ] - ], + List[Tuple[str, List[str]]], + List[str], ] ] = ..., string_if_invalid: str = ..., @@ -85,32 +62,14 @@ class Engine: self, template_loaders: Union[ List[List[Union[Dict[str, str], str]]], - List[ - Union[ - Tuple[ - str, - Union[ - Dict[str, str], - List[Tuple[str, Dict[str, str]]], - List[str], - ], - ], - str, - ] - ], + List[Tuple[str, List[str]]], + List[str], ], ) -> List[Loader]: ... def find_template_loader( self, loader: Union[ - List[Union[Dict[str, str], str]], - Tuple[ - str, - Union[ - Dict[str, str], List[Tuple[str, Dict[str, str]]], List[str] - ], - ], - str, + List[Union[Dict[str, str], str]], Tuple[str, List[str]], str ], ) -> Loader: ... def find_template( @@ -119,62 +78,6 @@ class Engine: def from_string(self, template_code: str) -> Template: ... def get_template(self, template_name: str) -> Template: ... def render_to_string( - self, - template_name: str, - context: Optional[ - Union[ - Dict[str, Callable], - Dict[str, Dict[Union[int, str], str]], - Dict[str, Dict[str, Callable]], - Dict[str, Dict[str, Dict[str, str]]], - Dict[str, Dict[str, List[Tuple[str, int]]]], - Dict[str, Dict[str, Tuple[str, str, str, str]]], - Dict[str, List[Dict[str, Union[List[int], int]]]], - Dict[str, List[Dict[str, Union[int, str]]]], - Dict[str, List[List[Tuple[int, str]]]], - Dict[str, List[Union[List[SafeText], str]]], - Dict[str, List[Template]], - Dict[str, Optional[int]], - Dict[str, Optional[str]], - Dict[ - str, Tuple[Dict[str, str], Dict[str, str], Dict[str, str]] - ], - Dict[ - str, - Tuple[ - Tuple[str, Union[int, str]], Tuple[str, Union[int, str]] - ], - ], - Dict[str, Tuple[int, int]], - Dict[str, Tuple[str, str]], - Dict[str, Union[Dict[str, int], List[Union[List[str], str]]]], - Dict[str, Union[Dict[str, int], str]], - Dict[ - str, - Union[ - List[ - Optional[ - Union[ - Dict[str, Union[List[str], str]], int, str - ] - ] - ], - str, - ], - ], - Dict[ - str, - Union[ - List[Optional[Union[Dict[str, date], int, str]]], int - ], - ], - Dict[str, Union[date, timedelta]], - Dict[str, Union[int, str]], - Dict[str, time], - Dict[str, Template], - Dict[str, float], - Dict[str, range], - ] - ] = ..., + self, template_name: str, context: Any = ... ) -> SafeText: ... def select_template(self, template_name_list: List[str]) -> Template: ... diff --git a/django-stubs/template/library.pyi b/django-stubs/template/library.pyi index 57e7c55..803f746 100644 --- a/django-stubs/template/library.pyi +++ b/django-stubs/template/library.pyi @@ -55,10 +55,7 @@ class TagHelperNode(Node): ) -> None: ... def get_resolved_arguments( self, context: Context - ) -> Tuple[ - Union[Dict[str, Union[SafeText, int]], List[Union[Context, int]]], - Union[Dict[Any, Any], Dict[str, Union[SafeText, int]], Dict[str, int]], - ]: ... + ) -> Tuple[List[int], Dict[str, Union[SafeText, int]]]: ... class SimpleNode(TagHelperNode): args: List[django.template.base.FilterExpression] @@ -102,7 +99,7 @@ def parse_bits( params: List[str], varargs: Optional[str], varkw: Optional[str], - defaults: Optional[Union[Tuple[bool, None], Tuple[str]]], + defaults: Optional[Tuple[Union[bool, str]]], kwonly: List[str], kwonly_defaults: Optional[Dict[str, int]], takes_context: Optional[bool], diff --git a/django-stubs/template/loader.pyi b/django-stubs/template/loader.pyi index ede54ec..9e7cc78 100644 --- a/django-stubs/template/loader.pyi +++ b/django-stubs/template/loader.pyi @@ -1,10 +1,6 @@ from typing import Any, Dict, List, Optional, Union -from django.contrib.auth.base_user import AbstractBaseUser from django.core.handlers.wsgi import WSGIRequest -from django.db.models.manager import Manager -from django.db.models.query import QuerySet -from django.forms.forms import Form from django.template.backends.django import Template from django.template.backends.dummy import Template from django.template.backends.jinja2 import Template @@ -20,15 +16,7 @@ def select_template( ) -> Union[Template, Template, Template]: ... def render_to_string( template_name: Union[List[str], str], - context: Optional[ - Union[ - Dict[str, Optional[str]], - Dict[str, Union[AbstractBaseUser, str]], - Dict[str, Union[Manager, QuerySet]], - Dict[str, Union[Form, str]], - Dict[str, bool], - ] - ] = ..., + context: Optional[Union[Dict[str, bool], Dict[str, str]]] = ..., request: Optional[WSGIRequest] = ..., using: Optional[str] = ..., ) -> str: ... diff --git a/django-stubs/template/loaders/cached.pyi b/django-stubs/template/loaders/cached.pyi index 3622cc7..7b51e6a 100644 --- a/django-stubs/template/loaders/cached.pyi +++ b/django-stubs/template/loaders/cached.pyi @@ -9,21 +9,8 @@ from .base import Loader as BaseLoader class Loader(BaseLoader): engine: django.template.engine.Engine template_cache: Dict[Any, Any] = ... - get_template_cache: Union[ - Dict[ - str, - Union[ - Type[django.template.exceptions.TemplateDoesNotExist], - django.template.base.Template, - ], - ], - Dict[ - str, - Union[ - django.template.base.Template, - django.template.exceptions.TemplateDoesNotExist, - ], - ], + get_template_cache: Dict[ + str, django.template.exceptions.TemplateDoesNotExist ] = ... loaders: List[django.template.loaders.base.Loader] = ... def __init__( diff --git a/django-stubs/template/response.pyi b/django-stubs/template/response.pyi index 4ad830c..f7bebfc 100644 --- a/django-stubs/template/response.pyi +++ b/django-stubs/template/response.pyi @@ -1,20 +1,14 @@ from datetime import datetime +from http.cookies import SimpleCookie from typing import Any, Callable, Dict, List, Optional, Tuple, Union from unittest.mock import MagicMock -from django.contrib.auth.forms import AuthenticationForm -from django.contrib.auth.views import LoginView -from django.contrib.sites.requests import RequestSite -from django.core.paginator import Page, Paginator from django.db.models.base import Model -from django.forms.forms import BaseForm from django.http import HttpResponse from django.http.request import HttpRequest from django.template.backends.django import Template from django.template.backends.jinja2 import Template from django.views.generic.base import TemplateResponseMixin -from django.views.generic.detail import DetailView -from django.views.generic.list import ListView from .loader import get_template, select_template @@ -29,42 +23,20 @@ class SimpleTemplateResponse(HttpResponse): template_name: Union[ List[str], django.template.backends.django.Template, str ] = ... - context_data: Optional[ - Union[Dict[str, Union[Callable, int]], Dict[str, str]] - ] = ... + context_data: Optional[Dict[str, str]] = ... using: Optional[str] = ... def __init__( self, template: Union[List[str], Template, str], context: Optional[ Union[ - Dict[str, Any], - Dict[str, List[Dict[str, Any]]], Dict[ - str, - Optional[ - Union[ - List[ - Dict[str, Optional[Union[datetime, Model, str]]] - ], - bool, - ListView, - ] - ], + str, List[Dict[str, Optional[Union[datetime, Model, str]]]] ], - Dict[str, Union[Callable, int]], - Dict[str, Union[Dict[str, str], DetailView]], - Dict[ - str, - Union[ - List[Dict[str, str]], bool, Page, Paginator, ListView - ], - ], - Dict[str, Union[List[str], str]], - Dict[ - str, Union[AuthenticationForm, LoginView, RequestSite, str] - ], - Dict[str, Union[Model, BaseForm, TemplateResponseMixin, str]], + Dict[str, List[str]], + Dict[str, Model], + Dict[str, TemplateResponseMixin], + Dict[str, str], MagicMock, ] ] = ..., @@ -80,59 +52,23 @@ class SimpleTemplateResponse(HttpResponse): self, context: Optional[ Union[ - Dict[str, Any], - Dict[str, List[Dict[str, Any]]], Dict[ - str, - Optional[ - Union[ - List[ - Dict[str, Optional[Union[datetime, Model, str]]] - ], - bool, - ListView, - ] - ], + str, List[Dict[str, Optional[Union[datetime, Model, str]]]] ], - Dict[str, Union[Callable, int]], - Dict[str, Union[Dict[str, str], DetailView]], - Dict[ - str, - Union[ - List[Dict[str, str]], bool, Page, Paginator, ListView - ], - ], - Dict[str, Union[List[str], str]], - Dict[ - str, Union[AuthenticationForm, LoginView, RequestSite, str] - ], - Dict[str, Union[Model, BaseForm, TemplateResponseMixin, str]], + Dict[str, List[str]], + Dict[str, Model], + Dict[str, TemplateResponseMixin], + Dict[str, str], MagicMock, ] ], ) -> Optional[ Union[ - Dict[str, Any], - Dict[str, List[Dict[str, Any]]], - Dict[ - str, - Optional[ - Union[ - List[Dict[str, Optional[Union[datetime, Model, str]]]], - bool, - ListView, - ] - ], - ], - Dict[str, Union[Callable, int]], - Dict[str, Union[Dict[str, str], DetailView]], - Dict[ - str, - Union[List[Dict[str, str]], bool, Page, Paginator, ListView], - ], - Dict[str, Union[List[str], str]], - Dict[str, Union[AuthenticationForm, LoginView, RequestSite, str]], - Dict[str, Union[Model, BaseForm, TemplateResponseMixin, str]], + Dict[str, List[Dict[str, Optional[Union[datetime, Model, str]]]]], + Dict[str, List[str]], + Dict[str, Model], + Dict[str, TemplateResponseMixin], + Dict[str, str], MagicMock, ] ]: ... @@ -155,63 +91,25 @@ class TemplateResponse(SimpleTemplateResponse): context: django.template.context.RequestContext context_data: Optional[ Union[ - Dict[str, Any], - Dict[str, List[Dict[str, Any]]], Dict[ str, - Optional[ - Union[ - List[ - Dict[ + List[ + Dict[ + str, + Optional[ + Union[ + datetime.datetime, + django.db.models.base.Model, str, - Optional[ - Union[ - datetime.datetime, - django.db.models.base.Model, - str, - ] - ], ] ], - bool, - django.views.generic.list.ListView, ] ], ], - Dict[str, Union[Callable, int]], - Dict[ - str, - Union[Dict[str, str], django.views.generic.detail.DetailView], - ], - Dict[ - str, - Union[ - List[Dict[str, str]], - bool, - django.core.paginator.Page, - django.core.paginator.Paginator, - django.views.generic.list.ListView, - ], - ], - Dict[str, Union[List[str], str]], - Dict[ - str, - Union[ - django.contrib.auth.forms.AuthenticationForm, - django.contrib.auth.views.LoginView, - django.contrib.sites.requests.RequestSite, - str, - ], - ], - Dict[ - str, - Union[ - django.db.models.base.Model, - django.forms.forms.BaseForm, - django.views.generic.base.TemplateResponseMixin, - str, - ], - ], + Dict[str, List[str]], + Dict[str, django.db.models.base.Model], + Dict[str, django.views.generic.base.TemplateResponseMixin], + Dict[str, str], unittest.mock.MagicMock, ] ] @@ -235,33 +133,13 @@ class TemplateResponse(SimpleTemplateResponse): template: Union[List[str], Template, str], context: Optional[ Union[ - Dict[str, Any], - Dict[str, List[Dict[str, Any]]], Dict[ - str, - Optional[ - Union[ - List[ - Dict[str, Optional[Union[datetime, Model, str]]] - ], - bool, - ListView, - ] - ], + str, List[Dict[str, Optional[Union[datetime, Model, str]]]] ], - Dict[str, Union[Callable, int]], - Dict[str, Union[Dict[str, str], DetailView]], - Dict[ - str, - Union[ - List[Dict[str, str]], bool, Page, Paginator, ListView - ], - ], - Dict[str, Union[List[str], str]], - Dict[ - str, Union[AuthenticationForm, LoginView, RequestSite, str] - ], - Dict[str, Union[Model, BaseForm, TemplateResponseMixin, str]], + Dict[str, List[str]], + Dict[str, Model], + Dict[str, TemplateResponseMixin], + Dict[str, str], MagicMock, ] ] = ..., diff --git a/django-stubs/templatetags/l10n.pyi b/django-stubs/templatetags/l10n.pyi index 16d48c9..c4cd726 100644 --- a/django-stubs/templatetags/l10n.pyi +++ b/django-stubs/templatetags/l10n.pyi @@ -2,7 +2,7 @@ from datetime import date from typing import Any, List, Optional, Union from django.template import Node -from django.template.base import Parser, Token +from django.template.base import NodeList, Parser, Token from django.template.context import Context from django.utils.safestring import SafeText @@ -14,9 +14,11 @@ def unlocalize(value: Union[date, float]) -> str: ... class LocalizeNode(Node): origin: django.template.base.Origin token: django.template.base.Token - nodelist: List[Any] = ... + nodelist: Union[List[Any], django.template.base.NodeList] = ... use_l10n: bool = ... - def __init__(self, nodelist: List[Any], use_l10n: bool) -> None: ... + def __init__( + self, nodelist: Union[List[Any], NodeList], use_l10n: bool + ) -> None: ... def render(self, context: Context) -> SafeText: ... def localize_tag(parser: Parser, token: Token) -> LocalizeNode: ... diff --git a/django-stubs/test/client.pyi b/django-stubs/test/client.pyi index f0f2bb2..a196f29 100644 --- a/django-stubs/test/client.pyi +++ b/django-stubs/test/client.pyi @@ -1,19 +1,17 @@ from datetime import date -from io import BufferedRandom, BufferedReader, BytesIO, StringIO -from tempfile import _TemporaryFileWrapper -from typing import Any, Callable, Dict, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, List, Optional, Union from django.contrib.auth.models import User from django.contrib.sessions.backends.base import SessionBase -from django.core.files.uploadedfile import SimpleUploadedFile from django.core.handlers.base import BaseHandler from django.core.handlers.wsgi import WSGIRequest from django.dispatch.dispatcher import Signal -from django.http.request import HttpRequest +from django.http.request import HttpRequest, QueryDict from django.http.response import (HttpResponse, HttpResponseBase, HttpResponseRedirect) from django.template.base import Template from django.template.context import Context +from django.test.utils import ContextList class RedirectCycleError(Exception): @@ -37,27 +35,7 @@ class ClientHandler(BaseHandler): ) -> None: ... def __call__(self, environ: Dict[str, Any]) -> HttpResponseBase: ... -def encode_multipart( - boundary: str, - data: Union[ - Dict[str, Union[List[int], List[str], int]], - Dict[str, Union[List[int], int, str]], - Dict[str, Union[List[str], int, str]], - Dict[str, Union[Tuple[str, str, str], int, str]], - Dict[ - str, - Union[ - Tuple[_TemporaryFileWrapper, _TemporaryFileWrapper], - str, - _TemporaryFileWrapper, - ], - ], - Dict[str, Union[BufferedReader, str]], - Dict[str, Union[BytesIO, StringIO, _TemporaryFileWrapper]], - Dict[str, BufferedRandom], - Dict[str, SimpleUploadedFile], - ], -) -> bytes: ... +def encode_multipart(boundary: str, data: Dict[str, Any]) -> bytes: ... def encode_file(boundary: str, key: str, file: Any) -> List[bytes]: ... class RequestFactory: @@ -70,42 +48,14 @@ class RequestFactory: def get( self, path: str, - data: Optional[ - Union[ - Dict[str, Union[Tuple[str, str, str], str]], - Dict[str, Union[int, str]], - Dict[str, date], - str, - ] - ] = ..., + data: Optional[Union[Dict[str, date], QueryDict, str]] = ..., secure: bool = ..., **extra: Any ) -> Union[WSGIRequest, HttpResponseBase]: ... def post( self, path: str, - data: Optional[ - Union[ - Dict[str, Union[List[int], List[str], int]], - Dict[str, Union[List[int], int, str]], - Dict[str, Union[List[str], int, str]], - Dict[str, Union[Tuple[str, str, str], int, str]], - Dict[ - str, - Union[ - Tuple[_TemporaryFileWrapper, _TemporaryFileWrapper], - str, - _TemporaryFileWrapper, - ], - ], - Dict[str, Union[BufferedReader, str]], - Dict[str, Union[BytesIO, StringIO, _TemporaryFileWrapper]], - Dict[str, BufferedRandom], - Dict[str, SimpleUploadedFile], - bytes, - str, - ] - ] = ..., + data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any @@ -181,13 +131,7 @@ class Client(RequestFactory): def get( self, path: str, - data: Optional[ - Union[ - Dict[str, Union[Tuple[str, str, str], str]], - Dict[str, Union[int, str]], - str, - ] - ] = ..., + data: Optional[Union[Dict[str, Union[int, str]], QueryDict, str]] = ..., follow: bool = ..., secure: bool = ..., **extra: Any @@ -195,28 +139,7 @@ class Client(RequestFactory): def post( self, path: str, - data: Optional[ - Union[ - Dict[str, Union[List[int], List[str], int]], - Dict[str, Union[List[int], int, str]], - Dict[str, Union[List[str], int, str]], - Dict[str, Union[Tuple[str, str, str], int, str]], - Dict[ - str, - Union[ - Tuple[_TemporaryFileWrapper, _TemporaryFileWrapper], - str, - _TemporaryFileWrapper, - ], - ], - Dict[str, Union[BufferedReader, str]], - Dict[str, Union[BytesIO, StringIO, _TemporaryFileWrapper]], - Dict[str, BufferedRandom], - Dict[str, SimpleUploadedFile], - bytes, - str, - ] - ] = ..., + data: Any = ..., content_type: str = ..., follow: bool = ..., secure: bool = ..., diff --git a/django-stubs/test/testcases.pyi b/django-stubs/test/testcases.pyi index a066567..60604b3 100644 --- a/django-stubs/test/testcases.pyi +++ b/django-stubs/test/testcases.pyi @@ -6,9 +6,7 @@ from typing import (Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union) from unittest.runner import TextTestResult -from django.contrib.staticfiles.handlers import StaticFilesHandler from django.core.handlers.wsgi import WSGIHandler -from django.core.management.commands.dumpdata import ProxyModelWarning from django.core.servers.basehttp import WSGIRequestHandler from django.db.backends.sqlite3.base import DatabaseWrapper from django.db.models.base import Model @@ -17,9 +15,8 @@ from django.forms.fields import EmailField from django.http.response import HttpResponse, HttpResponseBase from django.template.context import Context from django.test.html import Element -from django.test.utils import (CaptureQueriesContext, modify_settings, - override_settings) -from django.utils.deprecation import RemovedInDjango30Warning +from django.test.utils import (CaptureQueriesContext, ContextList, + modify_settings, override_settings) from django.utils.safestring import SafeText @@ -146,15 +143,7 @@ class SimpleTestCase(unittest.TestCase): ) -> Optional[_GeneratorContextManager]: ... def assertWarnsMessage( self, - expected_warning: Type[ - Union[ - DeprecationWarning, - RuntimeWarning, - UserWarning, - ProxyModelWarning, - RemovedInDjango30Warning, - ] - ], + expected_warning: Type[Exception], expected_message: str, *args: Any, **kwargs: Any @@ -206,13 +195,11 @@ class TransactionTestCase(SimpleTestCase): self, qs: Union[Iterator[Any], List[Model], QuerySet, RawQuerySet], values: Union[ - List[Optional[str]], - List[Tuple[Any, Any]], - List[Tuple[Model, Model]], - List[Tuple[Model, int, int]], - List[Tuple[str, Type[Model], int]], + List[None], + List[Tuple[str, str]], List[date], List[int], + List[str], Set[str], QuerySet, ], @@ -275,19 +262,14 @@ class LiveServerThread(threading.Thread): port: int = ... is_ready: threading.Event = ... error: Optional[django.core.exceptions.ImproperlyConfigured] = ... - static_handler: Type[ - Union[ - django.contrib.staticfiles.handlers.StaticFilesHandler, - django.test.testcases._StaticFilesHandler, - ] - ] = ... + static_handler: Type[django.core.handlers.wsgi.WSGIHandler] = ... connections_override: Dict[ str, django.db.backends.sqlite3.base.DatabaseWrapper ] = ... def __init__( self, host: str, - static_handler: Type[Union[StaticFilesHandler, _StaticFilesHandler]], + static_handler: Type[WSGIHandler], connections_override: Dict[str, DatabaseWrapper] = ..., port: int = ..., ) -> None: ... diff --git a/django-stubs/test/utils.pyi b/django-stubs/test/utils.pyi index d98494c..f0f23de 100644 --- a/django-stubs/test/utils.pyi +++ b/django-stubs/test/utils.pyi @@ -65,143 +65,7 @@ class TestContextDecorator: class override_settings(TestContextDecorator): attr_name: None kwarg_name: None - options: Union[ - Dict[str, Dict[str, Callable]], - Dict[ - str, - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Callable, Dict[str, Union[Dict[str, bool], bool]] - ], - ], - Dict[ - str, Union[Dict[str, Union[Dict[str, bool], bool]], int] - ], - Dict[ - str, Union[Dict[str, Union[Dict[str, bool], bool]], str] - ], - ], - ], - ], - Dict[ - str, - Dict[ - str, - Union[ - Dict[str, Union[Callable, Dict[str, int], str]], - Dict[str, Union[Dict[str, int], int, str]], - ], - ], - ], - Dict[str, List[Dict[str, Union[Dict[Any, Any], bool, str]]]], - Dict[ - str, - List[ - Union[ - Dict[ - str, - Union[ - Dict[str, List[Tuple[str, Dict[str, str]]]], - bool, - str, - ], - ], - Dict[str, Union[Dict[str, List[str]], str]], - ] - ], - ], - Dict[ - str, - List[ - Union[ - Dict[str, Union[Dict[str, int], bool, str]], - Dict[str, Union[Dict[str, str], str]], - ] - ], - ], - Dict[str, List[unittest.mock.Mock]], - Dict[str, Optional[Union[List[str], bool]]], - Dict[str, Optional[Union[bool, str]]], - Dict[str, Tuple[Tuple[str, str], Tuple[str, str]]], - Dict[str, Type[Any]], - Dict[str, Union[Callable, bool]], - Dict[str, Union[Dict[int, None], bool]], - Dict[ - str, - Union[ - Dict[str, Dict[str, Optional[str]]], List[Tuple[str, str]], str - ], - ], - Dict[str, Union[Dict[str, Optional[str]], List[str]]], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, Dict[str, Union[List[str], bool, str]]], int - ], - ], - str, - ], - ], - Dict[ - str, - Union[ - Dict[ - str, - Union[ - Dict[str, Union[Callable, str]], - Dict[str, Union[Dict[str, int], str]], - Dict[str, Union[int, str]], - ], - ], - bool, - ], - ], - Dict[ - str, - Union[Dict[str, Union[Dict[str, str], str]], List[str], int, str], - ], - Dict[ - str, - Union[ - List[ - Dict[str, Union[Dict[str, List[Any]], List[Any], bool, str]] - ], - List[str], - ], - ], - Dict[ - str, - Union[ - List[ - Dict[str, Union[Dict[str, List[str]], List[str], bool, str]] - ], - List[Union[Tuple[str, str], str]], - int, - str, - ], - ], - Dict[ - str, - Union[ - List[Dict[str, Union[Dict[str, Tuple[str]], List[str], str]]], - List[str], - int, - str, - ], - ], - Dict[str, Union[List[Dict[str, Union[List[Any], bool, str]]], int]], - Dict[str, Union[List[int], List[str], str]], - Dict[str, Union[Tuple[str], str]], - Dict[str, Union[float, str]], - Dict[str, bytes], - ] = ... + options: Dict[str, Any] = ... def __init__(self, **kwargs: Any) -> None: ... wrapped: Union[django.conf.Settings, django.conf.UserSettingsHolder] = ... def enable(self) -> None: ... @@ -217,9 +81,7 @@ class modify_settings(override_settings): attr_name: None kwarg_name: None wrapped: Union[django.conf.Settings, django.conf.UserSettingsHolder] - operations: List[ - Tuple[str, Union[Dict[str, List[str]], Dict[str, str]]] - ] = ... + operations: List[Tuple[str, Dict[str, Union[List[str], str]]]] = ... def __init__(self, *args: Any, **kwargs: Any) -> None: ... def save_options(self, test_func: Type[SimpleTestCase]) -> None: ... options: Dict[str, List[Union[Tuple[str, str], str]]] = ... @@ -262,9 +124,8 @@ class CaptureQueriesContext: class ignore_warnings(TestContextDecorator): attr_name: None kwarg_name: None - ignore_kwargs: Union[ - Dict[str, Type[django.utils.deprecation.RemovedInDjango30Warning]], - Dict[str, str], + ignore_kwargs: Dict[ + str, Union[Type[django.utils.deprecation.RemovedInDjango30Warning], str] ] = ... filter_func: Callable = ... def __init__(self, **kwargs: Any) -> None: ... diff --git a/django-stubs/urls/base.pyi b/django-stubs/urls/base.pyi index 832479b..b1dc0b7 100644 --- a/django-stubs/urls/base.pyi +++ b/django-stubs/urls/base.pyi @@ -12,13 +12,10 @@ def resolve(path: str, urlconf: Optional[str] = ...) -> ResolverMatch: ... def reverse( viewname: Optional[Union[Callable, str]], urlconf: Optional[str] = ..., - args: Optional[Union[List[Union[int, str]], List[UUID], Tuple]] = ..., + args: Optional[Union[List[UUID], Tuple]] = ..., kwargs: Optional[ Union[ - Dict[str, None], - Dict[str, Union[int, str]], - Dict[str, bytes], - Dict[str, UUID], + Dict[str, None], Dict[str, bytes], Dict[str, str], Dict[str, UUID] ] ] = ..., current_app: Optional[str] = ..., diff --git a/django-stubs/urls/conf.pyi b/django-stubs/urls/conf.pyi index 8e8b0fd..d757196 100644 --- a/django-stubs/urls/conf.pyi +++ b/django-stubs/urls/conf.pyi @@ -11,12 +11,13 @@ def include( List[Tuple[str, Callable]], List[URLPattern], List[URLResolver], - Tuple[List[URLPattern], str, str], - Tuple[str, str], + Tuple[List[URLResolver], str], str, ], namespace: Optional[str] = ..., -) -> Union[Tuple[None, None, None], Tuple[str, str, str]]: ... +) -> Union[ + Tuple[List[Any], str, str], Tuple[List[URLResolver], None, None] +]: ... path: Any re_path: Any diff --git a/django-stubs/urls/resolvers.pyi b/django-stubs/urls/resolvers.pyi index 6ee2b4f..53fc350 100644 --- a/django-stubs/urls/resolvers.pyi +++ b/django-stubs/urls/resolvers.pyi @@ -1,6 +1,7 @@ +from collections import OrderedDict from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union -from uuid import UUID +from django.contrib.flatpages.sitemaps import FlatPageSitemap from django.contrib.sitemaps import Sitemap from django.core.checks.messages import CheckMessage, Warning from django.utils.datastructures import MultiValueDict @@ -13,13 +14,7 @@ from .utils import get_callable class ResolverMatch: func: Callable = ... args: Tuple = ... - kwargs: Union[ - Dict[str, Dict[str, django.contrib.sitemaps.Sitemap]], - Dict[str, Union[Dict[str, Type[django.contrib.sitemaps.Sitemap]], str]], - Dict[str, Union[int, str]], - Dict[str, bytes], - Dict[str, uuid.UUID], - ] = ... + kwargs: Dict[str, Any] = ... url_name: Optional[str] = ... app_names: List[str] = ... app_name: str = ... @@ -30,13 +25,7 @@ class ResolverMatch: self, func: Callable, args: Tuple, - kwargs: Union[ - Dict[str, Dict[str, Sitemap]], - Dict[str, Union[Dict[str, Type[Sitemap]], str]], - Dict[str, Union[int, str]], - Dict[str, bytes], - Dict[str, UUID], - ], + kwargs: Dict[str, Any], url_name: Optional[str] = ..., app_names: Optional[List[Optional[str]]] = ..., namespaces: Optional[List[Optional[str]]] = ..., @@ -45,9 +34,11 @@ class ResolverMatch: self, index: int ) -> Union[ Callable, + Dict[str, Dict[str, Type[FlatPageSitemap]]], Dict[str, Dict[str, Sitemap]], - Dict[str, Union[Dict[str, Type[Sitemap]], str]], - Dict[str, Union[int, str]], + Dict[str, OrderedDict], + Dict[str, int], + Dict[str, str], Tuple, ]: ... @@ -83,30 +74,13 @@ class RegexPattern(CheckURLMixin): class RoutePattern(CheckURLMixin): regex: Any = ... name: Optional[str] = ... - converters: Union[ - Dict[ - str, - Union[ - django.urls.converters.IntConverter, - django.urls.converters.StringConverter, - ], - ], - Dict[str, django.urls.converters.UUIDConverter], - ] = ... + converters: Dict[str, django.urls.converters.UUIDConverter] = ... def __init__( self, route: str, name: Optional[str] = ..., is_endpoint: bool = ... ) -> None: ... def match( self, path: str - ) -> Optional[ - Tuple[ - str, - Tuple, - Union[ - Dict[str, Union[int, str]], Dict[str, bytes], Dict[str, UUID] - ], - ] - ]: ... + ) -> Optional[Tuple[str, Tuple, Dict[str, Union[int, str]]]]: ... def check(self) -> List[Warning]: ... class LocalePrefixPattern: @@ -127,10 +101,14 @@ class URLPattern: lookup_str: str pattern: django.urls.resolvers.CheckURLMixin = ... callback: Callable = ... - default_args: Union[ - Dict[str, Dict[str, django.contrib.sitemaps.Sitemap]], - Dict[str, Union[Dict[str, Type[django.contrib.sitemaps.Sitemap]], str]], - Dict[str, Union[int, str]], + default_args: Dict[ + str, + Union[ + Dict[str, Type[django.contrib.flatpages.sitemaps.FlatPageSitemap]], + Dict[str, django.contrib.sitemaps.Sitemap], + collections.OrderedDict, + str, + ], ] = ... name: Optional[str] = ... def __init__( @@ -139,9 +117,10 @@ class URLPattern: callback: Callable, default_args: Optional[ Union[ + Dict[str, Dict[str, Type[FlatPageSitemap]]], Dict[str, Dict[str, Sitemap]], - Dict[str, Union[Dict[str, Type[Sitemap]], str]], - Dict[str, Union[int, str]], + Dict[str, OrderedDict], + Dict[str, str], ] ] = ..., name: Optional[str] = ..., @@ -151,27 +130,8 @@ class URLPattern: def lookup_str(self) -> str: ... class URLResolver: - url_patterns: Union[ - List[Tuple[str, Callable]], - List[ - Union[ - django.urls.resolvers.URLPattern, - django.urls.resolvers.URLResolver, - ] - ], - ] - urlconf_module: Optional[ - Union[ - List[Tuple[str, Callable]], - List[ - Union[ - django.urls.resolvers.URLPattern, - django.urls.resolvers.URLResolver, - ] - ], - Type[Any], - ] - ] + url_patterns: List[Tuple[str, Callable]] + urlconf_module: Optional[Union[List[Tuple[str, Callable]], Type[Any]]] pattern: Union[ django.urls.resolvers.CheckURLMixin, django.urls.resolvers.LocalePrefixPattern, @@ -180,18 +140,14 @@ class URLResolver: Union[ List[List[Any]], List[Tuple[str, Callable]], - List[ - Union[ - django.urls.resolvers.URLPattern, - django.urls.resolvers.URLResolver, - ] - ], + List[django.urls.resolvers.URLPattern], + List[django.urls.resolvers.URLResolver], Type[Any], str, ] ] = ... callback: None = ... - default_kwargs: Union[Dict[str, Dict[Any, Any]], Dict[str, str]] = ... + default_kwargs: Dict[str, Union[Dict[Any, Any], str]] = ... namespace: Optional[str] = ... app_name: Optional[str] = ... def __init__( @@ -201,7 +157,8 @@ class URLResolver: Union[ List[List[Any]], List[Tuple[str, Callable]], - List[Union[URLPattern, URLResolver]], + List[URLPattern], + List[URLResolver], Type[Any], str, ] @@ -222,18 +179,8 @@ class URLResolver: def resolve(self, path: str) -> ResolverMatch: ... def urlconf_module( self - ) -> Optional[ - Union[ - List[Tuple[str, Callable]], - List[Union[URLPattern, URLResolver]], - Type[Any], - ] - ]: ... - def url_patterns( - self - ) -> Union[ - List[Tuple[str, Callable]], List[Union[URLPattern, URLResolver]] - ]: ... + ) -> Optional[Union[List[Tuple[str, Callable]], Type[Any]]]: ... + def url_patterns(self) -> List[Tuple[str, Callable]]: ... def resolve_error_handler( self, view_type: int ) -> Tuple[Callable, Dict[Any, Any]]: ... diff --git a/django-stubs/utils/autoreload.pyi b/django-stubs/utils/autoreload.pyi index 756488c..133d186 100644 --- a/django-stubs/utils/autoreload.pyi +++ b/django-stubs/utils/autoreload.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, List, Optional, Union +from typing import Any, Callable, List, Optional USE_INOTIFY: bool fd: Any @@ -7,9 +7,7 @@ FILE_MODIFIED: int I18N_MODIFIED: int def gen_filenames(only_new: bool = ...) -> List[str]: ... -def clean_files( - filelist: Union[List[Optional[bool]], List[Optional[str]]] -) -> List[str]: ... +def clean_files(filelist: List[Optional[str]]) -> List[str]: ... def reset_translations() -> None: ... def inotify_code_changed(): ... def code_changed(): ... diff --git a/django-stubs/utils/cache.pyi b/django-stubs/utils/cache.pyi index 73eed3e..65c9e1b 100644 --- a/django-stubs/utils/cache.pyi +++ b/django-stubs/utils/cache.pyi @@ -1,6 +1,5 @@ -from typing import Any, Optional, Tuple, Union +from typing import Any, Optional, Tuple -from django.core.cache import DefaultCacheProxy from django.core.cache.backends.base import BaseCache from django.core.cache.backends.locmem import LocMemCache from django.core.handlers.wsgi import WSGIRequest @@ -29,14 +28,12 @@ def get_cache_key( request: WSGIRequest, key_prefix: Optional[str] = ..., method: str = ..., - cache: Optional[Union[DefaultCacheProxy, backends.base.BaseCache]] = ..., + cache: Optional[BaseCache] = ..., ) -> Optional[str]: ... def learn_cache_key( request: WSGIRequest, response: HttpResponse, cache_timeout: Optional[float] = ..., key_prefix: Optional[str] = ..., - cache: Optional[ - Union[DefaultCacheProxy, backends.locmem.LocMemCache] - ] = ..., + cache: Optional[LocMemCache] = ..., ) -> str: ... diff --git a/django-stubs/utils/datastructures.pyi b/django-stubs/utils/datastructures.pyi index d97b14c..1d88ad5 100644 --- a/django-stubs/utils/datastructures.pyi +++ b/django-stubs/utils/datastructures.pyi @@ -5,13 +5,13 @@ from typing import (Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, from unittest.case import TestCase from uuid import UUID -from django.contrib.sitemaps import GenericSitemap, Sitemap +from django.contrib.sitemaps import GenericSitemap from django.core.files.uploadedfile import InMemoryUploadedFile, UploadedFile from django.db.models.base import Model from django.db.models.expressions import Combinable from django.test.testcases import SerializeMixin from django.test.utils import LoggingCaptureMixin -from django.urls.converters import IntConverter, StringConverter, UUIDConverter +from django.urls.converters import IntConverter, StringConverter class OrderedSet: @@ -20,10 +20,10 @@ class OrderedSet: self, iterable: Optional[ Union[ - List[Optional[int]], List[Tuple[str, str]], List[datetime], List[Combinable], + List[int], List[str], List[UUID], OrderedDict, @@ -51,7 +51,7 @@ class MultiValueDict(dict): key_to_list_mapping: Union[ Dict[str, List[List[Any]]], Dict[str, List[int]], - Dict[str, Optional[List[str]]], + Dict[str, List[str]], List[Tuple[str, Union[List[List[Any]], List[str]]]], Tuple, ] = ..., @@ -77,26 +77,7 @@ class MultiValueDict(dict): ) -> Union[ List[ Tuple[ - List[Tuple[str, List[str]]], - str, - Dict[str, Dict[str, GenericSitemap]], - Dict[str, Any], - ] - ], - List[ - Tuple[ - List[Tuple[str, List[str]]], - str, - Dict[str, Union[Dict[str, Type[Sitemap]], str]], - Union[Dict[str, StringConverter], Dict[str, UUIDConverter]], - ] - ], - List[ - Tuple[ - List[Tuple[str, List[str]]], - str, - Dict[str, int], - Union[Dict[str, IntConverter], Dict[str, StringConverter]], + List[Tuple[str, List[str]]], str, Dict[str, str], Dict[Any, Any] ] ], List[UploadedFile], @@ -109,22 +90,14 @@ class MultiValueDict(dict): Tuple[ List[Tuple[str, List[str]]], str, - Union[ - Dict[Any, Any], - Dict[str, Any], - Dict[str, Union[IntConverter, StringConverter]], - ], - Union[ - Dict[str, Any], - Dict[str, Union[IntConverter, StringConverter]], - Dict[str, UUIDConverter], - ], + Dict[str, Dict[str, GenericSitemap]], + Dict[str, Union[IntConverter, StringConverter]], ], UploadedFile, str, ], ) -> None: ... - def items(self) -> Iterator[Tuple[str, Union[UploadedFile, str]]]: ... + def items(self) -> Iterator[Tuple[str, InMemoryUploadedFile]]: ... def lists(self): ... def values(self) -> Iterator[str]: ... def copy(self) -> MultiValueDict: ... diff --git a/django-stubs/utils/dateformat.pyi b/django-stubs/utils/dateformat.pyi index 16bada7..2124930 100644 --- a/django-stubs/utils/dateformat.pyi +++ b/django-stubs/utils/dateformat.pyi @@ -1,4 +1,4 @@ -from datetime import date, time +from datetime import datetime from typing import Any, Optional, Union re_formatchars: Any @@ -8,9 +8,9 @@ class Formatter: def format(self, formatstr: str) -> str: ... class TimeFormat(Formatter): - data: Union[datetime.date, datetime.time, str] = ... + data: Union[datetime.datetime, str] = ... timezone: Optional[django.utils.timezone.FixedOffset] = ... - def __init__(self, obj: Union[date, time, str]) -> None: ... + def __init__(self, obj: Union[datetime, str]) -> None: ... def a(self) -> str: ... def A(self) -> str: ... def B(self) -> None: ... @@ -29,7 +29,7 @@ class TimeFormat(Formatter): def Z(self) -> Union[int, str]: ... class DateFormat(TimeFormat): - data: Union[datetime.date, datetime.time, str] + data: Union[datetime.datetime, str] timezone: Optional[django.utils.timezone.FixedOffset] year_days: Any = ... def b(self): ... @@ -57,5 +57,5 @@ class DateFormat(TimeFormat): def Y(self) -> int: ... def z(self) -> int: ... -def format(value: Union[date, time, str], format_string: str) -> str: ... -def time_format(value: Union[date, time, str], format_string: str) -> str: ... +def format(value: Union[datetime, str], format_string: str) -> str: ... +def time_format(value: Union[datetime, str], format_string: str) -> str: ... diff --git a/django-stubs/utils/deconstruct.pyi b/django-stubs/utils/deconstruct.pyi index 04b3861..01056d8 100644 --- a/django-stubs/utils/deconstruct.pyi +++ b/django-stubs/utils/deconstruct.pyi @@ -1,12 +1,9 @@ from typing import Any, Optional, Type, Union -from django.contrib.auth.validators import (ASCIIUsernameValidator, - UnicodeUsernameValidator) from django.contrib.postgres.validators import KeysValidator +from django.core.validators import RegexValidator def deconstructible( *args: Any, path: Optional[Any] = ... -) -> Type[ - Union[ASCIIUsernameValidator, UnicodeUsernameValidator, KeysValidator] -]: ... +) -> Type[Union[KeysValidator, RegexValidator]]: ... diff --git a/django-stubs/utils/decorators.pyi b/django-stubs/utils/decorators.pyi index 93add5f..26438b7 100644 --- a/django-stubs/utils/decorators.pyi +++ b/django-stubs/utils/decorators.pyi @@ -1,15 +1,11 @@ from typing import Any, Callable, Optional, Set, Tuple, Type, Union -from django.contrib.admindocs.middleware import XViewMiddleware -from django.contrib.auth.mixins import (LoginRequiredMixin, - PermissionRequiredMixin, - UserPassesTestMixin) +from django.contrib.auth.mixins import AccessMixin from django.contrib.messages.views import SuccessMessageMixin from django.middleware.cache import CacheMiddleware -from django.middleware.csrf import CsrfViewMiddleware -from django.middleware.http import ConditionalGetMiddleware from django.test.testcases import LiveServerTestCase -from django.views.generic.base import View +from django.utils.deprecation import MiddlewareMixin +from django.views.generic.base import TemplateResponseMixin, View class classonlymethod(classmethod): @@ -17,13 +13,7 @@ class classonlymethod(classmethod): self, instance: Optional[View], cls: Type[ - Union[ - LoginRequiredMixin, - PermissionRequiredMixin, - UserPassesTestMixin, - SuccessMessageMixin, - View, - ] + Union[AccessMixin, SuccessMessageMixin, TemplateResponseMixin, View] ] = ..., ) -> Callable: ... @@ -35,20 +25,11 @@ def decorator_from_middleware_with_args( middleware_class: Type[CacheMiddleware] ) -> Callable: ... def decorator_from_middleware( - middleware_class: Type[ - Union[XViewMiddleware, CsrfViewMiddleware, ConditionalGetMiddleware] - ] + middleware_class: Type[MiddlewareMixin] ) -> Callable: ... def available_attrs(fn: Any): ... def make_middleware_decorator( - middleware_class: Type[ - Union[ - XViewMiddleware, - CacheMiddleware, - CsrfViewMiddleware, - ConditionalGetMiddleware, - ] - ] + middleware_class: Type[MiddlewareMixin] ) -> Callable: ... class classproperty: diff --git a/django-stubs/utils/feedgenerator.pyi b/django-stubs/utils/feedgenerator.pyi index 7b2d01c..83a0bd1 100644 --- a/django-stubs/utils/feedgenerator.pyi +++ b/django-stubs/utils/feedgenerator.pyi @@ -52,15 +52,7 @@ class SyndicationFeed: def num_items(self): ... def root_attributes(self) -> Dict[Any, Any]: ... def add_root_elements(self, handler: Any) -> None: ... - def item_attributes( - self, - item: Union[ - Dict[str, Any], - Dict[ - str, Optional[Union[List[Enclosure], List[str], datetime, str]] - ], - ], - ) -> Dict[Any, Any]: ... + def item_attributes(self, item: Dict[str, Any]) -> Dict[Any, Any]: ... def add_item_elements(self, handler: Any, item: Any) -> None: ... def write(self, outfile: Any, encoding: Any) -> None: ... def writeString(self, encoding: str) -> str: ... @@ -96,10 +88,7 @@ class RssUserland091Feed(RssFeed): ) -> None: ... class Rss201rev2Feed(RssFeed): - feed: Union[ - Dict[str, Optional[Union[List[str], str]]], - Dict[str, Optional[Union[Tuple, str]]], - ] + feed: Dict[str, Optional[Union[List[str], Tuple, str]]] items: Union[ List[Dict[str, Any]], List[ @@ -117,20 +106,11 @@ class Rss201rev2Feed(RssFeed): ], ] def add_item_elements( - self, - handler: SimplerXMLGenerator, - item: Union[ - Dict[str, Any], - Dict[ - str, Optional[Union[List[Enclosure], List[str], datetime, str]] - ], - ], + self, handler: SimplerXMLGenerator, item: Dict[str, Any] ) -> None: ... class Atom1Feed(SyndicationFeed): - feed: Union[ - Dict[str, Optional[Union[Tuple, str]]], Dict[str, Union[List[str], str]] - ] + feed: Dict[str, Optional[Union[List[str], Tuple, str]]] items: Union[ List[ Dict[ @@ -160,11 +140,9 @@ class Atom1Feed(SyndicationFeed): def add_item_elements( self, handler: SimplerXMLGenerator, - item: Union[ - Dict[ - str, Optional[Union[List[Enclosure], List[str], datetime, str]] - ], - Dict[str, Optional[Union[List[str], Tuple, datetime, str]]], + item: Dict[ + str, + Optional[Union[List[Enclosure], List[str], Tuple, datetime, str]], ], ) -> None: ... diff --git a/django-stubs/utils/formats.pyi b/django-stubs/utils/formats.pyi index 157f3aa..a08ada7 100644 --- a/django-stubs/utils/formats.pyi +++ b/django-stubs/utils/formats.pyi @@ -1,4 +1,4 @@ -from datetime import date, time +from datetime import datetime from decimal import Decimal from typing import Any, Iterator, List, Optional, Union @@ -19,12 +19,12 @@ def get_format( get_format_lazy: Any def date_format( - value: Union[date, time, str], + value: Union[datetime, str], format: Optional[str] = ..., use_l10n: Optional[bool] = ..., ) -> str: ... def time_format( - value: Union[date, time, str], + value: Union[datetime, str], format: Optional[str] = ..., use_l10n: None = ..., ) -> str: ... @@ -36,7 +36,8 @@ def number_format( ) -> str: ... def localize(value: Any, use_l10n: Optional[bool] = ...) -> Any: ... def localize_input( - value: Any, default: Optional[str] = ... + value: Optional[Union[datetime, Decimal, float, str]], + default: Optional[str] = ..., ) -> Optional[str]: ... def sanitize_separators( value: Union[Decimal, int, str] diff --git a/django-stubs/utils/http.pyi b/django-stubs/utils/http.pyi index ff1a5ed..88e36da 100644 --- a/django-stubs/utils/http.pyi +++ b/django-stubs/utils/http.pyi @@ -1,5 +1,4 @@ -from datetime import date -from typing import Any, Dict, Iterator, List, Optional, Set, Tuple, Union +from typing import Any, Dict, List, Optional, Set, Tuple, Union ETAG_MATCH: Any MONTHS: Any @@ -14,22 +13,7 @@ def urlquote(url: str, safe: str = ...) -> str: ... def urlquote_plus(url: str, safe: str = ...) -> str: ... def urlunquote(quoted_url: str) -> str: ... def urlunquote_plus(quoted_url: str) -> str: ... -def urlencode( - query: Union[ - Dict[str, Iterator[Any]], - Dict[str, List[bytes]], - Dict[str, List[int]], - Dict[str, Union[Tuple[str, str, str], str]], - Dict[str, Union[int, str]], - Dict[str, bytearray], - Dict[str, bytes], - Dict[str, date], - List[Tuple[str, Union[int, str]]], - Tuple[Tuple[str, int], Tuple[str, int], Tuple[str, int]], - str, - ], - doseq: bool = ..., -) -> str: ... +def urlencode(query: Any, doseq: bool = ...) -> str: ... def cookie_date(epoch_seconds: float = ...) -> str: ... def http_date(epoch_seconds: float = ...) -> str: ... def parse_http_date(date: str) -> int: ... diff --git a/django-stubs/utils/itercompat.pyi b/django-stubs/utils/itercompat.pyi index c37a8e9..aafd802 100644 --- a/django-stubs/utils/itercompat.pyi +++ b/django-stubs/utils/itercompat.pyi @@ -8,28 +8,11 @@ def is_iterable( x: Optional[ Union[ List[List[Union[List[List[Union[List[List[str]], str]]], str]]], - List[ - Tuple[ - Union[Tuple[Tuple[int, str], Tuple[int, str]], str], - Union[Tuple[Tuple[int, str], Tuple[int, str]], str], - ] - ], - List[Tuple[int, int, int]], + List[Tuple[Optional[Union[int, str]], Union[int, str]]], List[CheckMessage], List[int], List[str], - Tuple[ - Tuple[ - Union[Tuple[Tuple[int, str], Tuple[int, str]], str], - Union[ - Tuple[Tuple[int, str], Tuple[int, str]], - Tuple[Tuple[str, str], Tuple[str, str]], - str, - ], - ] - ], - Tuple[str, str, str], - Tuple[_TemporaryFileWrapper, _TemporaryFileWrapper], + Tuple[Union[Tuple[str, str], _TemporaryFileWrapper]], int, ] ] diff --git a/django-stubs/utils/regex_helper.pyi b/django-stubs/utils/regex_helper.pyi index 0e18e52..4087741 100644 --- a/django-stubs/utils/regex_helper.pyi +++ b/django-stubs/utils/regex_helper.pyi @@ -16,7 +16,5 @@ def contains( source: Union[Group, NonCapture, str], inst: Type[Group] ) -> bool: ... def flatten_result( - source: Optional[ - Union[List[Union[Choice, Group, str]], List[Union[NonCapture, str]]] - ] + source: Optional[Union[List[Union[Choice, Group, str]], Group, NonCapture]] ) -> Tuple[List[str], List[List[str]]]: ... diff --git a/django-stubs/utils/timezone.pyi b/django-stubs/utils/timezone.pyi index 4b78264..b05db19 100644 --- a/django-stubs/utils/timezone.pyi +++ b/django-stubs/utils/timezone.pyi @@ -1,5 +1,5 @@ from contextlib import ContextDecorator -from datetime import date, datetime, time, timedelta, tzinfo +from datetime import date, datetime, timedelta, tzinfo from typing import Any, Optional, Union @@ -34,7 +34,7 @@ def localtime( value: Optional[datetime] = ..., timezone: Optional[FixedOffset] = ... ) -> datetime: ... def now() -> datetime: ... -def is_aware(value: Union[datetime, time]) -> bool: ... +def is_aware(value: datetime) -> bool: ... def is_naive(value: datetime) -> bool: ... def make_aware( value: datetime, diff --git a/django-stubs/utils/tree.pyi b/django-stubs/utils/tree.pyi index 7bb0383..5408cab 100644 --- a/django-stubs/utils/tree.pyi +++ b/django-stubs/utils/tree.pyi @@ -1,19 +1,15 @@ from typing import Any, Dict, List, Optional, Tuple, Union -from django.db.models.lookups import BuiltinLookup -from django.db.models.sql.where import NothingNode, WhereNode +from django.contrib.auth.models import User +from django.db.models.fields.related_lookups import RelatedLookupMixin +from django.db.models.lookups import BuiltinLookup, FieldGetDbPrepValueMixin +from django.db.models.sql.where import ExtraWhere, NothingNode class Node: default: str = ... children: Union[ - List[Tuple[str, int]], - List[ - Union[ - django.db.models.lookups.BuiltinLookup, - django.db.models.sql.where.WhereNode, - ] - ], + List[Tuple[str, int]], List[django.db.models.lookups.Contains] ] = ... connector: str = ... negated: bool = ... @@ -22,9 +18,12 @@ class Node: children: Optional[ Union[ List[Dict[str, str]], - List[Union[Tuple[str, Any], Node]], - List[Union[BuiltinLookup, WhereNode]], - List[Union[NothingNode, WhereNode]], + List[Tuple[str, List[User]]], + List[RelatedLookupMixin], + List[BuiltinLookup], + List[FieldGetDbPrepValueMixin], + List[NothingNode], + List[Node], ] ] = ..., connector: Optional[str] = ..., @@ -34,7 +33,12 @@ class Node: def __len__(self) -> int: ... def __bool__(self) -> bool: ... def __contains__(self, other: Tuple[str, int]) -> bool: ... - def __eq__(self, other: Any) -> bool: ... + def __eq__( + self, + other: Union[ + Tuple[str, List[Any]], BuiltinLookup, ExtraWhere, NothingNode, Node + ], + ) -> bool: ... def __hash__(self) -> int: ... def add(self, data: Any, conn_type: str, squash: bool = ...) -> Any: ... def negate(self) -> None: ... diff --git a/django-stubs/views/debug.pyi b/django-stubs/views/debug.pyi index 5a6520f..50f5a30 100644 --- a/django-stubs/views/debug.pyi +++ b/django-stubs/views/debug.pyi @@ -36,7 +36,7 @@ class SafeExceptionReporterFilter(ExceptionReporterFilter): ) -> QueryDict: ... def get_post_parameters( self, request: Optional[WSGIRequest] - ) -> Dict[Any, Any]: ... + ) -> Union[Dict[Any, Any], QueryDict]: ... def cleanse_special_types( self, request: Optional[WSGIRequest], value: Any ) -> Any: ... diff --git a/django-stubs/views/generic/base.pyi b/django-stubs/views/generic/base.pyi index e1f4ef9..d430bc3 100644 --- a/django-stubs/views/generic/base.pyi +++ b/django-stubs/views/generic/base.pyi @@ -2,36 +2,20 @@ from typing import Any, Callable, Dict, List, Optional, Union from unittest.mock import MagicMock from django.contrib.auth.forms import AuthenticationForm -from django.contrib.auth.views import LoginView -from django.contrib.sites.requests import RequestSite +from django.contrib.sites.models import Site from django.core.handlers.wsgi import WSGIRequest from django.core.paginator import Page, Paginator -from django.db.models.base import Model -from django.forms.forms import BaseForm from django.http.request import HttpRequest from django.http.response import (HttpResponse, HttpResponseNotAllowed, HttpResponseRedirect) from django.template.response import TemplateResponse -from django.views.generic.detail import DetailView -from django.views.generic.list import ListView, MultipleObjectMixin +from django.views.generic.list import ListView logger: Any class ContextMixin: extra_context: Any = ... - def get_context_data( - self, **kwargs: Any - ) -> Union[ - Dict[str, Any], - Dict[ - str, - Optional[Union[List[Dict[str, str]], bool, MultipleObjectMixin]], - ], - Dict[str, Union[Dict[str, str], DetailView]], - Dict[str, Union[List[Dict[str, str]], bool, Page, Paginator, ListView]], - Dict[str, Union[Model, BaseForm, TemplateResponseMixin]], - Dict[str, Union[Model, ContextMixin, str]], - ]: ... + def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ... class View: http_method_names: Any = ... @@ -61,13 +45,13 @@ class TemplateResponseMixin: context: Union[ Dict[str, Any], Dict[str, Optional[Union[List[Dict[str, str]], bool, ListView]]], - Dict[str, Union[Dict[str, str], DetailView]], Dict[ str, Union[List[Dict[str, str]], bool, Page, Paginator, ListView], ], - Dict[str, Union[AuthenticationForm, LoginView, RequestSite, str]], - Dict[str, Union[Model, BaseForm, TemplateResponseMixin, str]], + Dict[ + str, Union[AuthenticationForm, Site, TemplateResponseMixin, str] + ], MagicMock, ], **response_kwargs: Any @@ -89,7 +73,7 @@ class TemplateView(TemplateResponseMixin, ContextMixin, View): class RedirectView(View): args: Tuple - kwargs: Union[Dict[str, int], Dict[str, str]] + kwargs: Dict[str, Union[int, str]] request: django.core.handlers.wsgi.WSGIRequest permanent: bool = ... url: str = ... diff --git a/django-stubs/views/generic/detail.pyi b/django-stubs/views/generic/detail.pyi index 2a189ed..9918f70 100644 --- a/django-stubs/views/generic/detail.pyi +++ b/django-stubs/views/generic/detail.pyi @@ -3,7 +3,6 @@ from typing import Any, Dict, List, Optional, Union from django.core.handlers.wsgi import WSGIRequest from django.db.models.base import Model from django.db.models.query import QuerySet -from django.forms.models import ModelForm from django.template.response import TemplateResponse from django.views.generic.base import ContextMixin, TemplateResponseMixin, View @@ -22,13 +21,7 @@ class SingleObjectMixin(ContextMixin): def get_context_object_name( self, obj: Union[Dict[str, str], Model] ) -> Optional[str]: ... - def get_context_data( - self, **kwargs: Any - ) -> Union[ - Dict[str, Union[Dict[str, str], DetailView]], - Dict[str, Union[Model, ModelForm, SingleObjectTemplateResponseMixin]], - Dict[str, Union[Model, SingleObjectMixin, str]], - ]: ... + def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: ... class BaseDetailView(SingleObjectMixin, View): object: Any = ... diff --git a/django-stubs/views/generic/edit.pyi b/django-stubs/views/generic/edit.pyi index 0d4d694..be3a50f 100644 --- a/django-stubs/views/generic/edit.pyi +++ b/django-stubs/views/generic/edit.pyi @@ -7,6 +7,7 @@ from django.forms.models import ModelForm from django.http.request import HttpRequest from django.http.response import HttpResponse, HttpResponseRedirect from django.template.response import TemplateResponse +from django.utils.datastructures import MultiValueDict from django.views.generic.base import ContextMixin, TemplateResponseMixin, View from django.views.generic.detail import (BaseDetailView, SingleObjectMixin, SingleObjectTemplateResponseMixin) @@ -21,7 +22,9 @@ class FormMixin(ContextMixin): def get_prefix(self) -> None: ... def get_form_class(self) -> Type[Form]: ... def get_form(self, form_class: None = ...) -> BaseForm: ... - def get_form_kwargs(self) -> Dict[str, Optional[Dict[str, str]]]: ... + def get_form_kwargs( + self + ) -> Dict[str, Optional[Union[Dict[str, str], MultiValueDict]]]: ... def get_success_url(self) -> str: ... def form_valid(self, form: BaseForm) -> HttpResponseRedirect: ... def form_invalid(self, form: Form) -> TemplateResponse: ... @@ -35,7 +38,7 @@ class ModelFormMixin(FormMixin, SingleObjectMixin): def get_form_class(self) -> Type[ModelForm]: ... def get_form_kwargs( self - ) -> Dict[str, Optional[Union[Dict[Any, Any], Model]]]: ... + ) -> Dict[str, Optional[Union[Dict[Any, Any], Model, MultiValueDict]]]: ... def get_success_url(self) -> str: ... object: Any = ... def form_valid(self, form: ModelForm) -> HttpResponseRedirect: ... diff --git a/django-stubs/views/generic/list.pyi b/django-stubs/views/generic/list.pyi index acca4a9..dad5bee 100644 --- a/django-stubs/views/generic/list.pyi +++ b/django-stubs/views/generic/list.pyi @@ -1,6 +1,5 @@ from typing import Any, Dict, List, Optional, Tuple, Union -from django.contrib.admin.views.autocomplete import AutocompleteJsonView from django.core.handlers.wsgi import WSGIRequest from django.core.paginator import Page, Paginator from django.db.models.query import QuerySet @@ -22,7 +21,9 @@ class MultipleObjectMixin(ContextMixin): def get_ordering(self) -> Optional[Union[Tuple[str, str], str]]: ... def paginate_queryset( self, queryset: Union[List[Dict[str, str]], QuerySet], page_size: int - ) -> Tuple[Paginator, Page, bool, bool]: ... + ) -> Tuple[ + Paginator, Page, Union[List[Dict[str, str]], QuerySet], bool + ]: ... def get_paginate_by( self, queryset: Optional[Union[List[Dict[str, str]], QuerySet]] ) -> Optional[int]: ... @@ -41,15 +42,7 @@ class MultipleObjectMixin(ContextMixin): ) -> Optional[str]: ... def get_context_data( self, *, object_list: Optional[Any] = ..., **kwargs: Any - ) -> Union[ - Dict[str, Any], - Dict[ - str, - Optional[Union[List[Dict[str, str]], bool, MultipleObjectMixin]], - ], - Dict[str, Union[List[Dict[str, str]], bool, Page, Paginator, ListView]], - Dict[str, Union[bool, AutocompleteJsonView, Page, Paginator, QuerySet]], - ]: ... + ) -> Dict[str, Any]: ... class BaseListView(MultipleObjectMixin, View): object_list: Any = ...