Skip to content

Commit 6ccb678

Browse files
committed
Broaden type annotation for label to accept lazystr.
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 323f6db commit 6ccb678

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

django-stubs/contrib/admin/sites.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from django.http.request import HttpRequest
1111
from django.http.response import HttpResponse
1212
from django.template.response import TemplateResponse
1313
from django.urls import URLPattern, URLResolver
14-
from django.utils.functional import LazyObject
14+
from django.utils.functional import LazyObject, _StrOrPromise
1515

1616
if sys.version_info >= (3, 9):
1717
from weakref import WeakSet
@@ -77,7 +77,7 @@ class AdminSite:
7777
def i18n_javascript(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ...
7878
def logout(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ...
7979
def login(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ...
80-
def _build_app_dict(self, request: HttpRequest, label: Optional[str] = ...) -> Dict[str, Any]: ...
80+
def _build_app_dict(self, request: HttpRequest, label: Optional[_StrOrPromise] = ...) -> Dict[str, Any]: ...
8181
def get_app_list(self, request: HttpRequest) -> List[Any]: ...
8282
def index(self, request: HttpRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ...
8383
def app_index(

django-stubs/forms/boundfield.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BoundField:
1717
html_name: str = ...
1818
html_initial_name: str = ...
1919
html_initial_id: str = ...
20-
label: str = ...
20+
label: _StrOrPromise = ...
2121
help_text: _StrOrPromise = ...
2222
def __init__(self, form: BaseForm, field: Field, name: str) -> None: ...
2323
@property

django-stubs/forms/fields.pyi

+20-20
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _ClassLevelWidgetT = Any
2323

2424
class Field:
2525
initial: Any
26-
label: Optional[str]
26+
label: Optional[_StrOrPromise]
2727
required: bool
2828
widget: _ClassLevelWidgetT = ...
2929
hidden_widget: Type[Widget] = ...
@@ -43,7 +43,7 @@ class Field:
4343
*,
4444
required: bool = ...,
4545
widget: Optional[Union[Widget, Type[Widget]]] = ...,
46-
label: Optional[str] = ...,
46+
label: Optional[_StrOrPromise] = ...,
4747
initial: Optional[Any] = ...,
4848
help_text: _StrOrPromise = ...,
4949
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -78,7 +78,7 @@ class CharField(Field):
7878
empty_value: Optional[str] = ...,
7979
required: bool = ...,
8080
widget: Optional[Union[Widget, Type[Widget]]] = ...,
81-
label: Optional[str] = ...,
81+
label: Optional[_StrOrPromise] = ...,
8282
initial: Optional[Any] = ...,
8383
help_text: _StrOrPromise = ...,
8484
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -102,7 +102,7 @@ class IntegerField(Field):
102102
min_value: Optional[int] = ...,
103103
required: bool = ...,
104104
widget: Optional[Union[Widget, Type[Widget]]] = ...,
105-
label: Optional[str] = ...,
105+
label: Optional[_StrOrPromise] = ...,
106106
initial: Optional[Any] = ...,
107107
help_text: _StrOrPromise = ...,
108108
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -123,7 +123,7 @@ class FloatField(IntegerField):
123123
min_value: Union[int, float, None] = ...,
124124
required: bool = ...,
125125
widget: Optional[Union[Widget, Type[Widget]]] = ...,
126-
label: Optional[str] = ...,
126+
label: Optional[_StrOrPromise] = ...,
127127
initial: Optional[Any] = ...,
128128
help_text: _StrOrPromise = ...,
129129
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -149,7 +149,7 @@ class DecimalField(IntegerField):
149149
decimal_places: Optional[int] = ...,
150150
required: bool = ...,
151151
widget: Optional[Union[Widget, Type[Widget]]] = ...,
152-
label: Optional[str] = ...,
152+
label: Optional[_StrOrPromise] = ...,
153153
initial: Optional[Any] = ...,
154154
help_text: _StrOrPromise = ...,
155155
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -171,7 +171,7 @@ class BaseTemporalField(Field):
171171
input_formats: Optional[Any] = ...,
172172
required: bool = ...,
173173
widget: Optional[Union[Widget, Type[Widget]]] = ...,
174-
label: Optional[str] = ...,
174+
label: Optional[_StrOrPromise] = ...,
175175
initial: Optional[Any] = ...,
176176
help_text: _StrOrPromise = ...,
177177
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -215,7 +215,7 @@ class RegexField(CharField):
215215
empty_value: Optional[str] = ...,
216216
required: bool = ...,
217217
widget: Optional[Union[Widget, Type[Widget]]] = ...,
218-
label: Optional[str] = ...,
218+
label: Optional[_StrOrPromise] = ...,
219219
initial: Optional[Any] = ...,
220220
help_text: _StrOrPromise = ...,
221221
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -236,7 +236,7 @@ class EmailField(CharField):
236236
empty_value: Optional[str] = ...,
237237
required: bool = ...,
238238
widget: Optional[Union[Widget, Type[Widget]]] = ...,
239-
label: Optional[str] = ...,
239+
label: Optional[_StrOrPromise] = ...,
240240
initial: Optional[Any] = ...,
241241
help_text: _StrOrPromise = ...,
242242
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -256,7 +256,7 @@ class FileField(Field):
256256
allow_empty_file: bool = ...,
257257
required: bool = ...,
258258
widget: Optional[Union[Widget, Type[Widget]]] = ...,
259-
label: Optional[str] = ...,
259+
label: Optional[_StrOrPromise] = ...,
260260
initial: Optional[Any] = ...,
261261
help_text: _StrOrPromise = ...,
262262
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -285,7 +285,7 @@ class URLField(CharField):
285285
empty_value: Optional[str] = ...,
286286
required: bool = ...,
287287
widget: Optional[Union[Widget, Type[Widget]]] = ...,
288-
label: Optional[str] = ...,
288+
label: Optional[_StrOrPromise] = ...,
289289
initial: Optional[Any] = ...,
290290
help_text: _StrOrPromise = ...,
291291
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -323,7 +323,7 @@ class ChoiceField(Field):
323323
choices: Union[_FieldChoices, _ChoicesCallable] = ...,
324324
required: bool = ...,
325325
widget: Optional[Union[Widget, Type[Widget]]] = ...,
326-
label: Optional[str] = ...,
326+
label: Optional[_StrOrPromise] = ...,
327327
initial: Optional[Any] = ...,
328328
help_text: _StrOrPromise = ...,
329329
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -353,7 +353,7 @@ class TypedChoiceField(ChoiceField):
353353
choices: Union[_FieldChoices, _ChoicesCallable] = ...,
354354
required: bool = ...,
355355
widget: Optional[Union[Widget, Type[Widget]]] = ...,
356-
label: Optional[str] = ...,
356+
label: Optional[_StrOrPromise] = ...,
357357
initial: Optional[Any] = ...,
358358
help_text: _StrOrPromise = ...,
359359
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -381,7 +381,7 @@ class TypedMultipleChoiceField(MultipleChoiceField):
381381
choices: Union[_FieldChoices, _ChoicesCallable] = ...,
382382
required: bool = ...,
383383
widget: Optional[Union[Widget, Type[Widget]]] = ...,
384-
label: Optional[str] = ...,
384+
label: Optional[_StrOrPromise] = ...,
385385
initial: Optional[Any] = ...,
386386
help_text: _StrOrPromise = ...,
387387
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -402,7 +402,7 @@ class ComboField(Field):
402402
*,
403403
required: bool = ...,
404404
widget: Optional[Union[Widget, Type[Widget]]] = ...,
405-
label: Optional[str] = ...,
405+
label: Optional[_StrOrPromise] = ...,
406406
initial: Optional[Any] = ...,
407407
help_text: _StrOrPromise = ...,
408408
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -424,7 +424,7 @@ class MultiValueField(Field):
424424
require_all_fields: bool = ...,
425425
required: bool = ...,
426426
widget: Optional[Union[Widget, Type[Widget]]] = ...,
427-
label: Optional[str] = ...,
427+
label: Optional[_StrOrPromise] = ...,
428428
initial: Optional[Any] = ...,
429429
help_text: _StrOrPromise = ...,
430430
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -457,7 +457,7 @@ class FilePathField(ChoiceField):
457457
choices: Union[_FieldChoices, _ChoicesCallable] = ...,
458458
required: bool = ...,
459459
widget: Optional[Union[Widget, Type[Widget]]] = ...,
460-
label: Optional[str] = ...,
460+
label: Optional[_StrOrPromise] = ...,
461461
initial: Optional[Any] = ...,
462462
help_text: _StrOrPromise = ...,
463463
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -478,7 +478,7 @@ class SplitDateTimeField(MultiValueField):
478478
require_all_fields: bool = ...,
479479
required: bool = ...,
480480
widget: Optional[Union[Widget, Type[Widget]]] = ...,
481-
label: Optional[str] = ...,
481+
label: Optional[_StrOrPromise] = ...,
482482
initial: Optional[Any] = ...,
483483
help_text: _StrOrPromise = ...,
484484
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -499,7 +499,7 @@ class GenericIPAddressField(CharField):
499499
unpack_ipv4: bool = ...,
500500
required: bool = ...,
501501
widget: Optional[Union[Widget, Type[Widget]]] = ...,
502-
label: Optional[str] = ...,
502+
label: Optional[_StrOrPromise] = ...,
503503
initial: Optional[Any] = ...,
504504
help_text: _StrOrPromise = ...,
505505
error_messages: Optional[_ErrorMessagesT] = ...,
@@ -523,7 +523,7 @@ class SlugField(CharField):
523523
empty_value: Optional[str] = ...,
524524
required: bool = ...,
525525
widget: Optional[Union[Widget, Type[Widget]]] = ...,
526-
label: Optional[str] = ...,
526+
label: Optional[_StrOrPromise] = ...,
527527
initial: Optional[Any] = ...,
528528
help_text: _StrOrPromise = ...,
529529
error_messages: Optional[_ErrorMessagesT] = ...,

django-stubs/forms/models.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,18 @@ class ModelChoiceField(ChoiceField):
275275
validators: List[Any]
276276
default_error_messages: Dict[str, str] = ...
277277
iterator: Type[ModelChoiceIterator] = ...
278-
empty_label: Optional[str] = ...
278+
empty_label: Optional[_StrOrPromise] = ...
279279
queryset: Optional[QuerySet[models.Model]] = ...
280280
limit_choices_to: Optional[_AllLimitChoicesTo] = ...
281281
to_field_name: Optional[str] = ...
282282
def __init__(
283283
self,
284284
queryset: Union[None, Manager[models.Model], QuerySet[models.Model]],
285285
*,
286-
empty_label: Optional[str] = ...,
286+
empty_label: Optional[_StrOrPromise] = ...,
287287
required: bool = ...,
288288
widget: Optional[Union[Widget, Type[Widget]]] = ...,
289-
label: Optional[str] = ...,
289+
label: Optional[_StrOrPromise] = ...,
290290
initial: Optional[Any] = ...,
291291
help_text: _StrOrPromise = ...,
292292
to_field_name: Optional[str] = ...,
@@ -307,7 +307,7 @@ class ModelChoiceField(ChoiceField):
307307

308308
class ModelMultipleChoiceField(ModelChoiceField):
309309
disabled: bool
310-
empty_label: Optional[str]
310+
empty_label: Optional[_StrOrPromise]
311311
help_text: _StrOrPromise
312312
required: bool
313313
show_hidden_initial: bool

0 commit comments

Comments
 (0)