django-types 0.19.1__py3-none-any.whl → 0.21.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. django-stubs/contrib/admin/__init__.pyi +1 -0
  2. django-stubs/contrib/admin/actions.pyi +2 -2
  3. django-stubs/contrib/admin/decorators.pyi +4 -3
  4. django-stubs/contrib/admin/filters.pyi +5 -5
  5. django-stubs/contrib/admin/models.pyi +23 -11
  6. django-stubs/contrib/admin/options.pyi +67 -38
  7. django-stubs/contrib/admin/sites.pyi +11 -11
  8. django-stubs/contrib/admin/templatetags/base.pyi +1 -1
  9. django-stubs/contrib/admin/utils.pyi +2 -2
  10. django-stubs/contrib/admin/views/autocomplete.pyi +2 -2
  11. django-stubs/contrib/admin/views/main.pyi +8 -7
  12. django-stubs/contrib/admindocs/middleware.pyi +2 -2
  13. django-stubs/contrib/auth/__init__.pyi +14 -4
  14. django-stubs/contrib/auth/admin.pyi +2 -2
  15. django-stubs/contrib/auth/backends.pyi +22 -0
  16. django-stubs/contrib/auth/base_user.pyi +3 -3
  17. django-stubs/contrib/auth/forms.pyi +1 -1
  18. django-stubs/contrib/auth/middleware.pyi +1 -2
  19. django-stubs/contrib/auth/models.pyi +50 -26
  20. django-stubs/contrib/auth/views.pyi +1 -2
  21. django-stubs/contrib/contenttypes/fields.pyi +1 -1
  22. django-stubs/contrib/contenttypes/models.pyi +3 -1
  23. django-stubs/contrib/flatpages/middleware.pyi +2 -2
  24. django-stubs/contrib/flatpages/views.pyi +3 -3
  25. django-stubs/contrib/postgres/fields/array.pyi +6 -5
  26. django-stubs/contrib/postgres/fields/citext.pyi +13 -8
  27. django-stubs/contrib/postgres/fields/hstore.pyi +5 -4
  28. django-stubs/contrib/staticfiles/finders.pyi +1 -2
  29. django-stubs/contrib/staticfiles/views.pyi +2 -2
  30. django-stubs/contrib/syndication/views.pyi +4 -4
  31. django-stubs/core/cache/backends/base.pyi +9 -0
  32. django-stubs/core/exceptions.pyi +18 -11
  33. django-stubs/core/files/base.pyi +1 -1
  34. django-stubs/core/files/storage.pyi +2 -2
  35. django-stubs/core/mail/__init__.pyi +1 -1
  36. django-stubs/core/mail/backends/base.pyi +1 -0
  37. django-stubs/core/mail/message.pyi +6 -6
  38. django-stubs/core/serializers/json.pyi +1 -1
  39. django-stubs/core/servers/basehttp.pyi +2 -2
  40. django-stubs/db/backends/utils.pyi +1 -2
  41. django-stubs/db/migrations/recorder.pyi +1 -1
  42. django-stubs/db/models/base.pyi +9 -3
  43. django-stubs/db/models/constraints.pyi +1 -0
  44. django-stubs/db/models/enums.pyi +10 -19
  45. django-stubs/db/models/expressions.pyi +1 -1
  46. django-stubs/db/models/fields/__init__.pyi +227 -77
  47. django-stubs/db/models/fields/files.pyi +2 -2
  48. django-stubs/db/models/fields/json.pyi +10 -6
  49. django-stubs/db/models/fields/related.pyi +42 -20
  50. django-stubs/db/models/fields/related_descriptors.pyi +3 -3
  51. django-stubs/db/models/functions/__init__.pyi +2 -0
  52. django-stubs/db/models/functions/comparison.pyi +8 -0
  53. django-stubs/db/models/manager.pyi +11 -6
  54. django-stubs/db/models/query.pyi +4 -1
  55. django-stubs/db/models/query_utils.pyi +1 -0
  56. django-stubs/db/transaction.pyi +7 -1
  57. django-stubs/forms/boundfield.pyi +3 -1
  58. django-stubs/forms/forms.pyi +28 -35
  59. django-stubs/forms/formsets.pyi +98 -63
  60. django-stubs/forms/models.pyi +22 -17
  61. django-stubs/forms/renderers.pyi +26 -13
  62. django-stubs/forms/utils.pyi +38 -11
  63. django-stubs/http/cookie.pyi +3 -1
  64. django-stubs/http/request.pyi +43 -16
  65. django-stubs/http/response.pyi +38 -30
  66. django-stubs/shortcuts.pyi +1 -2
  67. django-stubs/template/backends/base.pyi +14 -5
  68. django-stubs/template/backends/django.pyi +24 -3
  69. django-stubs/template/backends/dummy.pyi +7 -6
  70. django-stubs/template/backends/jinja2.pyi +20 -2
  71. django-stubs/template/backends/utils.pyi +3 -3
  72. django-stubs/template/base.pyi +2 -2
  73. django-stubs/template/context.pyi +2 -2
  74. django-stubs/template/context_processors.pyi +1 -2
  75. django-stubs/template/library.pyi +79 -15
  76. django-stubs/template/loader.pyi +5 -3
  77. django-stubs/template/response.pyi +3 -3
  78. django-stubs/template/utils.pyi +6 -4
  79. django-stubs/test/client.pyi +176 -20
  80. django-stubs/test/testcases.pyi +4 -4
  81. django-stubs/test/utils.pyi +41 -55
  82. django-stubs/urls/base.pyi +18 -2
  83. django-stubs/urls/conf.pyi +7 -0
  84. django-stubs/utils/cache.pyi +4 -4
  85. django-stubs/utils/datastructures.pyi +5 -5
  86. django-stubs/utils/deconstruct.pyi +10 -2
  87. django-stubs/utils/log.pyi +1 -1
  88. django-stubs/utils/six.pyi +1 -1
  89. django-stubs/utils/translation/__init__.pyi +5 -3
  90. django-stubs/utils/translation/trans_real.pyi +2 -2
  91. django-stubs/views/decorators/csrf.pyi +1 -1
  92. django-stubs/views/generic/edit.pyi +1 -2
  93. {django_types-0.19.1.dist-info → django_types-0.21.0.dist-info}/METADATA +12 -8
  94. {django_types-0.19.1.dist-info → django_types-0.21.0.dist-info}/RECORD +96 -96
  95. {django_types-0.19.1.dist-info → django_types-0.21.0.dist-info}/WHEEL +1 -1
  96. {django_types-0.19.1.dist-info → django_types-0.21.0.dist-info}/LICENSE.txt +0 -0
@@ -1,90 +1,125 @@
1
- from collections.abc import Mapping, Sequence, Sized
2
- from typing import Any
1
+ from collections.abc import Iterator, Mapping
2
+ from typing import Any, Generic, TypeVar
3
3
 
4
- from django.forms import Form
4
+ from django.forms import BaseForm, Form
5
+ from django.forms.renderers import BaseRenderer
6
+ from django.forms.utils import ErrorDict, ErrorList, RenderableFormMixin
7
+ from django.forms.widgets import CheckboxInput, Media, NumberInput, Widget
5
8
 
6
- TOTAL_FORM_COUNT: str = ...
7
- INITIAL_FORM_COUNT: str = ...
8
- MIN_NUM_FORM_COUNT: str = ...
9
- MAX_NUM_FORM_COUNT: str = ...
10
- ORDERING_FIELD_NAME: str = ...
11
- DELETION_FIELD_NAME: str = ...
9
+ TOTAL_FORM_COUNT: str
10
+ INITIAL_FORM_COUNT: str
11
+ MIN_NUM_FORM_COUNT: str
12
+ MAX_NUM_FORM_COUNT: str
13
+ ORDERING_FIELD_NAME: str
14
+ DELETION_FIELD_NAME: str
12
15
 
13
- DEFAULT_MIN_NUM: int = ...
14
- DEFAULT_MAX_NUM: int = ...
16
+ DEFAULT_MIN_NUM: int
17
+ DEFAULT_MAX_NUM: int
15
18
 
16
- class ManagementForm(Form):
17
- cleaned_data: dict[str, int | None]
19
+ _BaseFormT = TypeVar("_BaseFormT", bound=BaseForm)
20
+
21
+ class ManagementForm(Form): ...
22
+
23
+ class BaseFormSet(Generic[_BaseFormT], RenderableFormMixin):
24
+ deletion_widget: type[CheckboxInput]
25
+ ordering_widget: type[NumberInput]
26
+ default_error_messages: dict[str, str]
27
+ template_name_div: str
28
+ template_name_p: str
29
+ template_name_table: str
30
+ template_name_ul: str
31
+
32
+ is_bound: bool
33
+ prefix: str
34
+ auto_id: str
35
+ data: dict[str, Any]
36
+ files: dict[str, Any]
37
+ initial: list[dict[str, Any]] | None
38
+ form_kwargs: dict[str, Any]
39
+ error_class: type[ErrorList]
40
+ error_messages: dict[str, Any]
18
41
 
19
- class BaseFormSet(Sized, Mapping[str, Any]):
20
- is_bound: Any = ...
21
- prefix: Any = ...
22
- auto_id: Any = ...
23
- data: Any = ...
24
- files: Any = ...
25
- initial: Any = ...
26
- form_kwargs: Any = ...
27
- error_class: Any = ...
28
42
  def __init__(
29
43
  self,
30
- data: Any | None = ...,
31
- files: Any | None = ...,
44
+ data: Mapping[str, Any] | None = ...,
45
+ files: Mapping[str, Any] | None = ...,
32
46
  auto_id: str = ...,
33
- prefix: Any | None = ...,
34
- initial: Any | None = ...,
35
- error_class: Any = ...,
36
- form_kwargs: Any | None = ...,
47
+ prefix: str | None = ...,
48
+ initial: list[dict[str, Any]] | None = ...,
49
+ error_class: type[ErrorList] = ...,
50
+ form_kwargs: dict[str, Any] | None = ...,
51
+ error_messages: dict[str, Any] | None = ...,
37
52
  ) -> None: ...
38
- def __iter__(self) -> Any: ...
39
- def __getitem__(self, index: Any) -> Any: ...
40
- def __len__(self) -> Any: ...
41
- def __bool__(self) -> Any: ...
42
- def management_form(self) -> Any: ...
43
- def total_form_count(self) -> Any: ...
44
- def initial_form_count(self) -> Any: ...
53
+ def __iter__(self) -> Iterator[_BaseFormT]: ...
54
+ def __getitem__(self, index: int) -> _BaseFormT: ...
55
+ def __len__(self) -> int: ...
56
+ def __bool__(self) -> bool: ...
57
+ @property
58
+ def management_form(self) -> ManagementForm: ...
59
+ def total_form_count(self) -> int: ...
60
+ def initial_form_count(self) -> int: ...
45
61
  @property
46
- def forms(self) -> Any: ...
47
- def get_form_kwargs(self, index: Any) -> Any: ...
62
+ def forms(self) -> list[_BaseFormT]: ...
63
+ def get_form_kwargs(self, index: int) -> dict[str, Any]: ...
48
64
  @property
49
- def initial_forms(self) -> Any: ...
65
+ def initial_forms(self) -> list[_BaseFormT]: ...
50
66
  @property
51
- def extra_forms(self) -> Any: ...
67
+ def extra_forms(self) -> list[_BaseFormT]: ...
52
68
  @property
53
- def empty_form(self) -> Any: ...
69
+ def empty_form(self) -> _BaseFormT: ...
54
70
  @property
55
- def cleaned_data(self) -> Any: ...
71
+ def cleaned_data(self) -> list[dict[str, Any]]: ...
56
72
  @property
57
- def deleted_forms(self) -> Any: ...
73
+ def deleted_forms(self) -> list[_BaseFormT]: ...
58
74
  @property
59
- def ordered_forms(self) -> Any: ...
75
+ def ordered_forms(self) -> list[_BaseFormT]: ...
60
76
  @classmethod
61
- def get_default_prefix(cls) -> Any: ...
62
- def non_form_errors(self) -> Any: ...
77
+ def get_default_prefix(cls) -> str: ...
78
+ @classmethod
79
+ def get_deletion_widget(cls) -> type[Widget]: ...
80
+ @classmethod
81
+ def get_ordering_widget(cls) -> type[Widget]: ...
82
+ def non_form_errors(self) -> ErrorList: ...
63
83
  @property
64
- def errors(self) -> Any: ...
65
- def total_error_count(self) -> Any: ...
66
- def is_valid(self) -> Any: ...
67
- def full_clean(self) -> Any: ...
84
+ def errors(self) -> list[ErrorDict]: ...
85
+ def total_error_count(self) -> int: ...
86
+ def is_valid(self) -> bool: ...
87
+ def full_clean(self) -> None: ...
68
88
  def clean(self) -> None: ...
69
- def has_changed(self) -> Any: ...
70
- def add_fields(self, form: Any, index: Any) -> None: ...
71
- def add_prefix(self, index: Any) -> Any: ...
72
- def is_multipart(self) -> Any: ...
89
+ def has_changed(self) -> bool: ...
90
+ def add_fields(self, form: _BaseFormT, index: int) -> None: ...
91
+ def add_prefix(self, index: int) -> str: ...
92
+ def is_multipart(self) -> bool: ...
73
93
  @property
74
- def media(self) -> Any: ...
75
- def as_table(self) -> Any: ...
76
- def as_p(self) -> Any: ...
77
- def as_ul(self) -> Any: ...
94
+ def media(self) -> Media: ...
95
+ def get_context(self) -> dict[str, Any]: ...
96
+
97
+ # Dynamic class produced by formset_factory
98
+ class _FormSet(BaseFormSet[_BaseFormT]):
99
+ form: type[_BaseFormT]
100
+ extra: int
101
+ can_order: bool
102
+ can_delete: bool
103
+ can_delete_extra: bool
104
+ min_num: int
105
+ max_num: int
106
+ absolute_max: int
107
+ validate_min: bool
108
+ validate_max: bool
109
+ renderer: BaseRenderer
78
110
 
79
111
  def formset_factory(
80
- form: Any,
81
- formset: Any = ...,
112
+ form: type[_BaseFormT],
113
+ formset: type[BaseFormSet[_BaseFormT]] = ...,
82
114
  extra: int = ...,
83
115
  can_order: bool = ...,
84
116
  can_delete: bool = ...,
85
- max_num: Any | None = ...,
117
+ max_num: int | None = ...,
86
118
  validate_max: bool = ...,
87
- min_num: Any | None = ...,
119
+ min_num: int | None = ...,
88
120
  validate_min: bool = ...,
89
- ) -> Any: ...
90
- def all_valid(formsets: Sequence[Any]) -> bool: ...
121
+ absolute_max: int | None = ...,
122
+ can_delete_extra: bool = ...,
123
+ renderer: BaseRenderer | None = ...,
124
+ ) -> type[_FormSet[_BaseFormT]]: ...
125
+ def all_valid(formsets: Iterator[BaseFormSet[Any]]) -> bool: ...
@@ -7,8 +7,7 @@ from collections.abc import (
7
7
  Sequence,
8
8
  )
9
9
  from datetime import datetime
10
- from typing import Any, ClassVar, TypeVar
11
- from typing_extensions import Literal
10
+ from typing import Any, ClassVar, Literal, Protocol, TypeVar
12
11
  from unittest.mock import MagicMock
13
12
  from uuid import UUID
14
13
 
@@ -33,6 +32,11 @@ _ErrorMessages = dict[str, dict[str, str]]
33
32
 
34
33
  _M = TypeVar("_M", bound=Model)
35
34
 
35
+ # Modeled from example:
36
+ # https://docs.djangoproject.com/en/4.2/topics/forms/modelforms/#overriding-the-default-fields
37
+ class FormFieldCallback(Protocol):
38
+ def __call__(self, db_field: models.Field[Any, Any], **kwargs: Any) -> Field: ...
39
+
36
40
  def construct_instance(
37
41
  form: BaseForm,
38
42
  instance: _M,
@@ -42,12 +46,13 @@ def construct_instance(
42
46
  def model_to_dict(
43
47
  instance: Model, fields: _Fields | None = ..., exclude: _Fields | None = ...
44
48
  ) -> dict[str, Any]: ...
49
+ def apply_limit_choices_to_to_formfield(formfield: Field) -> None: ...
45
50
  def fields_for_model(
46
51
  model: type[Model],
47
52
  fields: _Fields | None = ...,
48
53
  exclude: _Fields | None = ...,
49
54
  widgets: dict[str, type[Input]] | dict[str, Widget] | None = ...,
50
- formfield_callback: Callable[..., Any] | str | None = ...,
55
+ formfield_callback: FormFieldCallback | None = ...,
51
56
  localized_fields: tuple[str] | str | None = ...,
52
57
  labels: _Labels | None = ...,
53
58
  help_texts: dict[str, str] | None = ...,
@@ -58,15 +63,16 @@ def fields_for_model(
58
63
  ) -> dict[str, Any]: ...
59
64
 
60
65
  class ModelFormOptions:
61
- model: type[Model] | None = ...
62
- fields: _Fields | None = ...
63
- exclude: _Fields | None = ...
64
- widgets: dict[str, Widget | Input] | None = ...
65
- localized_fields: tuple[str] | str | None = ...
66
- labels: _Labels | None = ...
67
- help_texts: dict[str, str] | None = ...
68
- error_messages: _ErrorMessages | None = ...
69
- field_classes: dict[str, type[Field]] | None = ...
66
+ model: type[Model] | None
67
+ fields: _Fields | None
68
+ exclude: _Fields | None
69
+ widgets: dict[str, Widget | Input] | None
70
+ localized_fields: tuple[str] | str | None
71
+ labels: _Labels | None
72
+ help_texts: dict[str, str] | None
73
+ error_messages: _ErrorMessages | None
74
+ field_classes: dict[str, type[Field]] | None
75
+ formfield_callback: FormFieldCallback | None
70
76
  def __init__(self, options: type | None = ...) -> None: ...
71
77
 
72
78
  class ModelFormMetaclass(DeclarativeFieldsMetaclass): ...
@@ -92,7 +98,7 @@ class BaseModelForm(BaseForm):
92
98
  def save(self, commit: bool = ...) -> Any: ...
93
99
 
94
100
  class ModelForm(BaseModelForm, metaclass=ModelFormMetaclass):
95
- base_fields: ClassVar[dict[str, Field]] = ...
101
+ _meta: ClassVar[ModelFormOptions]
96
102
 
97
103
  def modelform_factory(
98
104
  model: type[Model],
@@ -108,7 +114,7 @@ def modelform_factory(
108
114
  field_classes: MutableMapping[str, type[Field]] | None = ...,
109
115
  ) -> type[ModelForm]: ...
110
116
 
111
- class BaseModelFormSet(BaseFormSet):
117
+ class BaseModelFormSet(BaseFormSet[ModelForm]):
112
118
  model: Any = ...
113
119
  unique_fields: Any = ...
114
120
  queryset: Any = ...
@@ -251,7 +257,7 @@ class ModelChoiceField(ChoiceField):
251
257
  empty_label: str | None = ...
252
258
  queryset: Any = ...
253
259
  limit_choices_to: dict[str, Any] | Callable[[], Any] | None = ...
254
- to_field_name: None = ...
260
+ to_field_name: str | None = ...
255
261
  def __init__(
256
262
  self,
257
263
  queryset: Manager[Any] | QuerySet[Any] | None,
@@ -262,7 +268,7 @@ class ModelChoiceField(ChoiceField):
262
268
  label: Any | None = ...,
263
269
  initial: Any | None = ...,
264
270
  help_text: str = ...,
265
- to_field_name: Any | None = ...,
271
+ to_field_name: str | None = ...,
266
272
  limit_choices_to: dict[str, Any] | Callable[[], Any] | None = ...,
267
273
  **kwargs: Any
268
274
  ) -> None: ...
@@ -280,7 +286,6 @@ class ModelChoiceField(ChoiceField):
280
286
 
281
287
  class ModelMultipleChoiceField(ModelChoiceField):
282
288
  disabled: bool
283
- empty_label: None
284
289
  help_text: str
285
290
  required: bool
286
291
  show_hidden_initial: bool
@@ -1,27 +1,40 @@
1
+ from collections.abc import Mapping
1
2
  from typing import Any
3
+ from typing_extensions import override
2
4
 
3
- from django.template import Template
4
- from django.template.backends.base import BaseEngine
5
+ from django.http.request import HttpRequest
6
+ from django.template.backends.base import BaseEngine, _BaseTemplate
7
+ from django.template.backends.django import Template as DjangoTemplate
8
+ from django.template.backends.jinja2 import Template as Jinja2Template
9
+ from django.utils.safestring import SafeText
5
10
 
6
- ROOT: Any
7
-
8
- def get_default_renderer() -> DjangoTemplates: ...
11
+ def get_default_renderer() -> BaseRenderer: ...
9
12
 
10
13
  class BaseRenderer:
11
- def get_template(self, template_name: str) -> Any: ...
14
+ form_template_name: str
15
+ formset_template_name: str
16
+ def get_template(self, template_name: str) -> _BaseTemplate: ...
12
17
  def render(
13
- self, template_name: str, context: dict[str, Any], request: None = ...
14
- ) -> str: ...
18
+ self,
19
+ template_name: str,
20
+ context: Mapping[str, Any],
21
+ request: HttpRequest | None = ...,
22
+ ) -> SafeText: ...
15
23
 
16
24
  class EngineMixin:
17
- def get_template(self, template_name: str) -> Any: ...
25
+ backend: BaseEngine
26
+ def get_template(self, template_name: str) -> _BaseTemplate: ...
27
+ @property
18
28
  def engine(self) -> BaseEngine: ...
19
29
 
20
30
  class DjangoTemplates(EngineMixin, BaseRenderer):
21
- backend: Any = ...
31
+ @override
32
+ def get_template(self, template_name: str) -> DjangoTemplate: ...
22
33
 
23
34
  class Jinja2(EngineMixin, BaseRenderer):
24
- backend: Any = ...
35
+ @override
36
+ def get_template(self, template_name: str) -> Jinja2Template: ...
25
37
 
26
- class TemplatesSetting(BaseRenderer):
27
- def get_template(self, template_name: str) -> Template: ...
38
+ class DjangoDivFormRenderer(DjangoTemplates): ...
39
+ class Jinja2DivFormRenderer(Jinja2): ...
40
+ class TemplatesSetting(BaseRenderer): ...
@@ -1,34 +1,61 @@
1
1
  from collections import UserList
2
- from collections.abc import Sequence
2
+ from collections.abc import Mapping, Sequence
3
3
  from datetime import datetime
4
4
  from typing import Any
5
5
 
6
6
  from django.core.exceptions import ValidationError
7
+ from django.forms.renderers import BaseRenderer
7
8
  from django.utils.safestring import SafeText
8
9
 
9
10
  def pretty_name(name: str) -> str: ...
10
11
  def flatatt(attrs: dict[str, Any]) -> SafeText: ...
11
12
 
12
- class ErrorDict(dict[str, Any]):
13
+ class RenderableMixin:
14
+ def get_context(self) -> Mapping[str, Any]: ...
15
+ def render(
16
+ self,
17
+ template_name: str | None = ...,
18
+ context: Mapping[str, Any] | None = ...,
19
+ renderer: BaseRenderer | None = ...,
20
+ ) -> SafeText: ...
21
+
22
+ class RenderableFormMixin(RenderableMixin):
23
+ def as_p(self) -> SafeText: ...
24
+ def as_table(self) -> SafeText: ...
25
+ def as_ul(self) -> SafeText: ...
26
+ def as_div(self) -> SafeText: ...
27
+
28
+ class RenderableErrorMixin(RenderableMixin):
29
+ def as_json(self, escape_html: bool = ...) -> str: ...
30
+ def as_text(self) -> SafeText: ...
31
+ def as_ul(self) -> SafeText: ...
32
+
33
+ class ErrorDict(dict[str, ErrorList], RenderableErrorMixin):
34
+ template_name: str
35
+ template_name_text: str
36
+ template_name_ul: str
37
+ renderer: BaseRenderer
38
+ def __init__(
39
+ self, *args: Any, renderer: BaseRenderer | None = ..., **kwargs: Any
40
+ ): ...
13
41
  def as_data(self) -> dict[str, list[ValidationError]]: ...
14
42
  def get_json_data(self, escape_html: bool = ...) -> dict[str, Any]: ...
15
- def as_json(self, escape_html: bool = ...) -> str: ...
16
- def as_ul(self) -> str: ...
17
- def as_text(self) -> str: ...
18
43
 
19
- class ErrorList(UserList[Any]):
44
+ class ErrorList(UserList[ValidationError | str], RenderableErrorMixin):
45
+ template_name: str
46
+ template_name_text: str
47
+ template_name_ul: str
20
48
  data: list[ValidationError | str]
21
- error_class: str = ...
49
+ error_class: str
50
+ renderer: BaseRenderer
22
51
  def __init__(
23
52
  self,
24
- initlist: ErrorList | Sequence[str | Exception] | None = ...,
53
+ initlist: Sequence[str | Exception] | None = ...,
25
54
  error_class: str | None = ...,
55
+ renderer: BaseRenderer | None = None,
26
56
  ) -> None: ...
27
57
  def as_data(self) -> list[ValidationError]: ...
28
58
  def get_json_data(self, escape_html: bool = ...) -> list[dict[str, str]]: ...
29
- def as_json(self, escape_html: bool = ...) -> str: ...
30
- def as_ul(self) -> str: ...
31
- def as_text(self) -> str: ...
32
59
 
33
60
  def from_current_timezone(value: datetime) -> datetime: ...
34
61
  def to_current_timezone(value: datetime) -> datetime: ...
@@ -1,3 +1,5 @@
1
- from http.cookies import SimpleCookie as SimpleCookie
1
+ from http import cookies
2
+
3
+ SimpleCookie = cookies.SimpleCookie
2
4
 
3
5
  def parse_cookie(cookie: str) -> dict[str, str]: ...
@@ -1,11 +1,9 @@
1
1
  from collections.abc import Iterable, Mapping
2
- from io import BytesIO
3
2
  from re import Pattern
4
- from typing import Any, BinaryIO, overload
3
+ from typing import Any, BinaryIO, TypeVar, overload
5
4
  from typing_extensions import Self
6
5
 
7
- from django.contrib.auth.base_user import AbstractBaseUser
8
- from django.contrib.auth.models import AnonymousUser
6
+ from django.contrib.auth.models import _AnyUser
9
7
  from django.contrib.sessions.backends.base import SessionBase
10
8
  from django.contrib.sites.models import Site
11
9
  from django.core.files import uploadedfile, uploadhandler
@@ -19,7 +17,7 @@ from django.utils.datastructures import (
19
17
  RAISE_ERROR: object = ...
20
18
  host_validation_re: Pattern[str] = ...
21
19
 
22
- class UnreadablePostError(IOError): ...
20
+ class UnreadablePostError(OSError): ...
23
21
  class RawPostDataException(Exception): ...
24
22
 
25
23
  UploadHandlerList = (
@@ -27,14 +25,26 @@ UploadHandlerList = (
27
25
  | ImmutableList[uploadhandler.FileUploadHandler]
28
26
  )
29
27
 
30
- class HttpHeaders(CaseInsensitiveMapping[str, str]):
28
+ T = TypeVar("T")
29
+
30
+ class HttpHeaders(CaseInsensitiveMapping[str]):
31
31
  HTTP_PREFIX: str = ...
32
32
  UNPREFIXED_HEADERS: set[str] = ...
33
33
  def __init__(self, environ: Mapping[str, Any]) -> None: ...
34
34
  @classmethod
35
35
  def parse_header_name(cls, header: str) -> str | None: ...
36
+ @classmethod
37
+ def to_wsgi_name(cls, header: str) -> str: ...
38
+ @classmethod
39
+ def to_asgi_name(cls, header: str) -> str: ...
40
+ @classmethod
41
+ def to_wsgi_names(cls, headers: Mapping[str, T]) -> Mapping[str, T]: ...
42
+ @classmethod
43
+ def to_asgi_names(cls, headers: Mapping[str, T]) -> Mapping[str, T]: ...
44
+
45
+ class MediaType: ...
36
46
 
37
- class HttpRequest(BytesIO):
47
+ class HttpRequest:
38
48
  GET: QueryDict = ...
39
49
  POST: QueryDict = ...
40
50
  COOKIES: dict[str, str] = ...
@@ -43,15 +53,13 @@ class HttpRequest(BytesIO):
43
53
  path: str = ...
44
54
  path_info: str = ...
45
55
  method: str | None = ...
46
- resolver_match: ResolverMatch = ...
56
+ resolver_match: ResolverMatch | None = ...
47
57
  content_type: str | None = ...
48
58
  content_params: dict[str, str] | None = ...
49
- user: AbstractBaseUser | AnonymousUser
50
- site: Site
51
- session: SessionBase
52
- encoding: str | None = ...
53
- upload_handlers: UploadHandlerList = ...
54
59
  def __init__(self) -> None: ...
60
+ @property
61
+ def accepted_types(self) -> list[MediaType]: ...
62
+ def accepts(self, media_type: str) -> bool: ...
55
63
  def get_host(self) -> str: ...
56
64
  def get_port(self) -> str: ...
57
65
  def get_full_path(self, force_append_slash: bool = ...) -> str: ...
@@ -59,15 +67,19 @@ class HttpRequest(BytesIO):
59
67
  def get_signed_cookie(
60
68
  self,
61
69
  key: str,
62
- default: Any = ...,
70
+ default: T = ...,
63
71
  salt: str = ...,
64
72
  max_age: int | None = ...,
65
- ) -> str | None: ...
73
+ ) -> str | T: ...
66
74
  def get_raw_uri(self) -> str: ...
67
75
  def build_absolute_uri(self, location: str | None = ...) -> str: ...
68
76
  @property
69
- def scheme(self) -> str | None: ...
77
+ def scheme(self) -> str: ...
70
78
  def is_secure(self) -> bool: ...
79
+ @property
80
+ def encoding(self) -> str: ...
81
+ @property
82
+ def upload_handlers(self) -> UploadHandlerList: ...
71
83
  def is_ajax(self) -> bool: ...
72
84
  def parse_file_upload(
73
85
  self, META: Mapping[str, Any], post_data: BinaryIO
@@ -77,6 +89,21 @@ class HttpRequest(BytesIO):
77
89
  @property
78
90
  def body(self) -> bytes: ...
79
91
  def _load_post_and_files(self) -> None: ...
92
+ def close(self) -> None: ...
93
+ def read(self, *args: Any, **kwargs: Any) -> bytes: ...
94
+ def readline(self, *args: Any, **kwargs: Any) -> bytes: ...
95
+ def __iter__(self) -> Iterable[bytes]: ...
96
+ def readlines(self) -> list[bytes]: ...
97
+
98
+ # Attributes added by optional parts of Django
99
+ # django.contrib.admin views:
100
+ current_app: str
101
+ # django.contrib.auth.middleware.AuthenticationMiddleware:
102
+ user: _AnyUser
103
+ # django.contrib.sites.middleware.CurrentSiteMiddleware
104
+ site: Site
105
+ # django.contrib.sessions.middleware.SessionMiddleware
106
+ session: SessionBase
80
107
 
81
108
  class QueryDict(MultiValueDict[str, str]):
82
109
  encoding: str = ...
@@ -1,23 +1,28 @@
1
1
  import datetime
2
- from collections.abc import AsyncIterable, Iterable, Iterator
2
+ from collections.abc import AsyncIterable, AsyncIterator, Iterable, Iterator
3
3
  from io import BytesIO
4
4
  from json import JSONEncoder
5
5
  from typing import Any, overload
6
+ from typing_extensions import Never
6
7
 
7
8
  from django.core.handlers.wsgi import WSGIRequest
8
9
  from django.http.cookie import SimpleCookie
9
10
  from django.template import Context, Template
10
11
  from django.test.client import Client
11
12
  from django.urls import ResolverMatch
13
+ from django.utils.datastructures import CaseInsensitiveMapping
14
+
15
+ class ResponseHeaders(CaseInsensitiveMapping[str]):
16
+ def pop(self, key: str, default: str | None = ...) -> str: ...
17
+ def setdefault(self, key: str, value: str) -> None: ...
12
18
 
13
19
  class BadHeaderError(ValueError): ...
14
20
 
15
- class HttpResponseBase(Iterable[Any]):
16
- status_code: int = ...
17
- cookies: SimpleCookie[str] = ...
18
- reason_phrase: str = ...
19
- charset: str = ...
20
- closed: bool = ...
21
+ class HttpResponseBase:
22
+ cookies: SimpleCookie # type: ignore [type-arg]
23
+ headers: ResponseHeaders
24
+ status_code: int
25
+ closed: bool
21
26
  def __init__(
22
27
  self,
23
28
  content_type: str | None = ...,
@@ -25,6 +30,10 @@ class HttpResponseBase(Iterable[Any]):
25
30
  reason: str | None = ...,
26
31
  charset: str | None = ...,
27
32
  ) -> None: ...
33
+ @property
34
+ def reason_phrase(self) -> str: ...
35
+ @property
36
+ def charset(self) -> str: ...
28
37
  def serialize_headers(self) -> bytes: ...
29
38
  def __setitem__(self, header: str | bytes, value: str | bytes | int) -> None: ...
30
39
  def __delitem__(self, header: str | bytes) -> None: ...
@@ -56,28 +65,30 @@ class HttpResponseBase(Iterable[Any]):
56
65
  ) -> None: ...
57
66
  def make_bytes(self, value: object) -> bytes: ...
58
67
  def close(self) -> None: ...
59
- def write(self, content: str | bytes) -> None: ...
60
68
  def flush(self) -> None: ...
61
- def tell(self) -> int: ...
62
69
  def readable(self) -> bool: ...
63
70
  def seekable(self) -> bool: ...
64
71
  def writable(self) -> bool: ...
65
- def writelines(self, lines: Iterable[object]) -> Any: ...
66
- def __iter__(self) -> Iterator[Any]: ...
67
72
 
68
- class HttpResponse(HttpResponseBase):
69
- content: Any
73
+ class HttpResponse(HttpResponseBase, Iterable[bytes]):
70
74
  csrf_cookie_set: bool
71
75
  redirect_chain: list[tuple[str, int]]
72
76
  sameorigin: bool
73
77
  test_server_port: str
74
78
  test_was_secure_request: bool
75
79
  xframe_options_exempt: bool
76
- streaming: bool = ...
77
- def __init__(self, content: object = ..., *args: Any, **kwargs: Any) -> None: ...
80
+ streaming: bool
81
+ def __init__(self, content: Any = ..., *args: Any, **kwargs: Any) -> None: ...
78
82
  def serialize(self) -> bytes: ...
79
83
  @property
80
- def url(self) -> str: ...
84
+ def content(self) -> bytes: ...
85
+ def __iter__(self) -> Iterator[bytes]: ...
86
+ def write(self, content: str | bytes) -> None: ...
87
+ def tell(self) -> int: ...
88
+ def getvalue(self) -> bytes: ...
89
+ def writable(self) -> bool: ...
90
+ def writelines(self, lines: Iterable[str | bytes]) -> None: ...
91
+
81
92
  # Attributes assigned by monkey-patching in test client ClientHandler.__call__()
82
93
  wsgi_request: WSGIRequest
83
94
  # Attributes assigned by monkey-patching in test client Client.request()
@@ -87,10 +98,9 @@ class HttpResponse(HttpResponseBase):
87
98
  context: Context
88
99
  resolver_match: ResolverMatch
89
100
  def json(self) -> Any: ...
90
- def getvalue(self) -> bytes: ...
91
101
 
92
- class StreamingHttpResponse(HttpResponseBase):
93
- content: Any
102
+ class StreamingHttpResponse(HttpResponseBase, Iterable[bytes], AsyncIterable[bytes]):
103
+ streaming: bool
94
104
  streaming_content: Iterable[bytes] | AsyncIterable[bytes]
95
105
  def __init__(
96
106
  self,
@@ -99,27 +109,25 @@ class StreamingHttpResponse(HttpResponseBase):
99
109
  **kwargs: Any
100
110
  ) -> None: ...
101
111
  def getvalue(self) -> bytes: ...
112
+ @property
113
+ def content(self) -> Never: ...
114
+ def __iter__(self) -> Iterator[bytes]: ...
115
+ def __aiter__(self) -> AsyncIterator[bytes]: ...
102
116
 
103
117
  class FileResponse(StreamingHttpResponse):
104
- client: Client
105
- context: None
106
- file_to_stream: BytesIO | None
107
- request: dict[str, str]
108
- resolver_match: ResolverMatch
109
- templates: list[Any]
110
- wsgi_request: WSGIRequest
111
- block_size: int = ...
112
- as_attachment: bool = ...
113
- filename: str = ...
118
+ block_size: int
119
+ as_attachment: bool
120
+ filename: str
114
121
  def __init__(
115
122
  self, *args: Any, as_attachment: bool = ..., filename: str = ..., **kwargs: Any
116
123
  ) -> None: ...
117
124
  def set_headers(self, filelike: BytesIO) -> None: ...
118
- def json(self) -> dict[str, Any]: ...
119
125
 
120
126
  class HttpResponseRedirectBase(HttpResponse):
121
127
  allowed_schemes: list[str] = ...
122
128
  def __init__(self, redirect_to: str, *args: Any, **kwargs: Any) -> None: ...
129
+ @property
130
+ def url(self) -> str: ...
123
131
 
124
132
  class HttpResponseRedirect(HttpResponseRedirectBase): ...
125
133
  class HttpResponsePermanentRedirect(HttpResponseRedirectBase): ...