Skip to content

Commit d532bc9

Browse files
committed
Add more attribute to fields
1 parent 85547a8 commit d532bc9

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

rest_framework-stubs/fields.pyi

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,35 @@ class Field:
5454
default_validators: List[Callable] = ...
5555
default_empty_html: Any = ...
5656
initial: Optional[Any] = ...
57+
read_only: bool = ...
58+
write_only: bool = ...
59+
required: bool = ...
60+
default: Any = ...
61+
initial: Any = ...
62+
source: Optional[str] = ...
63+
label: Optional[str] = ...
64+
help_text: Optional[str] = ...
65+
style: Optional[Mapping[str, Any]] = ...
66+
error_messages: Optional[Mapping[str, str]] = ...
67+
validators: Optional[List[_Validator]] = ...
68+
allow_null: bool = ...
69+
field_name: Optional[str] = ...
5770
# TODO: add Generic/Plugin support for parent
58-
parent: Optional[Any]
59-
validators: Optional[List[_Validator]]
71+
parent: Optional[Any] = ...
6072
def __init__(
6173
self,
6274
read_only: bool = ...,
6375
write_only: bool = ...,
6476
required: bool = ...,
6577
default: Any = ...,
6678
initial: Any = ...,
67-
source: Union[Callable, str] = ...,
79+
source: Optional[str] = ...,
6880
label: Optional[str] = ...,
6981
help_text: str = ...,
70-
allow_null: bool = ...,
71-
validators: Optional[Sequence[_Validator]] = ...,
72-
error_messages: Optional[Mapping[str, str]] = ...,
7382
style: Optional[Mapping[str, Any]] = ...,
83+
error_messages: Optional[Mapping[str, str]] = ...,
84+
validators: Optional[Sequence[_Validator]] = ...,
85+
allow_null: bool = ...,
7486
): ...
7587
def bind(self, field_name: str, parent: BaseSerializer) -> None: ...
7688
def get_validators(self) -> List[Callable]: ...
@@ -102,14 +114,15 @@ class NullBooleanField(Field):
102114
class CharField(Field):
103115
_pyi_field_actual_type: str
104116
_pyi_field_primitive_type: str
117+
allow_blank: bool = ...
105118
def __init__(
106119
self,
107120
read_only: bool = ...,
108121
write_only: bool = ...,
109122
required: bool = ...,
110123
default: Any = ...,
111124
initial: Any = ...,
112-
source: Union[Callable, str] = ...,
125+
source: Optional[str] = ...,
113126
label: Optional[str] = ...,
114127
help_text: str = ...,
115128
allow_null: bool = ...,
@@ -133,7 +146,7 @@ class RegexField(CharField):
133146
required: bool = ...,
134147
default: Any = ...,
135148
initial: Any = ...,
136-
source: Union[Callable, str] = ...,
149+
source: Optional[str] = ...,
137150
label: Optional[str] = ...,
138151
help_text: str = ...,
139152
allow_null: bool = ...,
@@ -155,7 +168,7 @@ class SlugField(CharField):
155168
required: bool = ...,
156169
default: Any = ...,
157170
initial: Any = ...,
158-
source: Union[Callable, str] = ...,
171+
source: Optional[str] = ...,
159172
label: Optional[str] = ...,
160173
help_text: str = ...,
161174
allow_null: bool = ...,
@@ -183,7 +196,7 @@ class UUIDField(Field):
183196
required: bool = ...,
184197
default: Any = ...,
185198
initial: Any = ...,
186-
source: Union[Callable, str] = ...,
199+
source: Optional[str] = ...,
187200
label: Optional[str] = ...,
188201
help_text: str = ...,
189202
allow_null: bool = ...,
@@ -201,7 +214,7 @@ class IPAddressField(CharField):
201214
required: bool = ...,
202215
default: Any = ...,
203216
initial: Any = ...,
204-
source: Union[Callable, str] = ...,
217+
source: Optional[str] = ...,
205218
label: Optional[str] = ...,
206219
help_text: str = ...,
207220
allow_null: bool = ...,
@@ -229,7 +242,7 @@ class IntegerField(Field):
229242
required: bool = ...,
230243
default: Any = ...,
231244
initial: Any = ...,
232-
source: Union[Callable, str] = ...,
245+
source: Optional[str] = ...,
233246
label: Optional[str] = ...,
234247
help_text: str = ...,
235248
allow_null: bool = ...,
@@ -252,7 +265,7 @@ class FloatField(Field):
252265
required: bool = ...,
253266
default: Any = ...,
254267
initial: Any = ...,
255-
source: Union[Callable, str] = ...,
268+
source: Optional[str] = ...,
256269
label: Optional[str] = ...,
257270
help_text: str = ...,
258271
allow_null: bool = ...,
@@ -277,7 +290,7 @@ class DecimalField(Field):
277290
required: bool = ...,
278291
default: Any = ...,
279292
initial: Any = ...,
280-
source: Union[Callable, str] = ...,
293+
source: Optional[str] = ...,
281294
label: Optional[str] = ...,
282295
help_text: str = ...,
283296
allow_null: bool = ...,
@@ -303,7 +316,7 @@ class DateTimeField(Field):
303316
required: bool = ...,
304317
default: Any = ...,
305318
initial: Any = ...,
306-
source: Union[Callable, str] = ...,
319+
source: Optional[str] = ...,
307320
label: Optional[str] = ...,
308321
help_text: str = ...,
309322
allow_null: bool = ...,
@@ -328,7 +341,7 @@ class DateField(Field):
328341
required: bool = ...,
329342
default: Any = ...,
330343
initial: Any = ...,
331-
source: Union[Callable, str] = ...,
344+
source: Optional[str] = ...,
332345
label: Optional[str] = ...,
333346
help_text: str = ...,
334347
allow_null: bool = ...,
@@ -351,7 +364,7 @@ class TimeField(Field):
351364
required: bool = ...,
352365
default: Any = ...,
353366
initial: Any = ...,
354-
source: Union[Callable, str] = ...,
367+
source: Optional[str] = ...,
355368
label: Optional[str] = ...,
356369
help_text: str = ...,
357370
allow_null: bool = ...,
@@ -372,7 +385,7 @@ class DurationField(Field):
372385
required: bool = ...,
373386
default: Any = ...,
374387
initial: Any = ...,
375-
source: Union[Callable, str] = ...,
388+
source: Optional[str] = ...,
376389
label: Optional[str] = ...,
377390
help_text: str = ...,
378391
allow_null: bool = ...,
@@ -387,6 +400,7 @@ class ChoiceField(Field):
387400
choices: Sequence[Any]
388401
html_cutoff: Optional[int] = ...
389402
html_cutoff_text: Optional[str] = ...
403+
allow_blank: bool = ...
390404
def __init__(
391405
self,
392406
choices: Sequence[Any],
@@ -398,7 +412,7 @@ class ChoiceField(Field):
398412
required: bool = ...,
399413
default: Any = ...,
400414
initial: Any = ...,
401-
source: Union[Callable, str] = ...,
415+
source: Optional[str] = ...,
402416
label: Optional[str] = ...,
403417
help_text: str = ...,
404418
allow_null: bool = ...,
@@ -411,6 +425,7 @@ class ChoiceField(Field):
411425
def _set_choices(self, choices: Sequence[Any]) -> None: ...
412426

413427
class MultipleChoiceField(ChoiceField):
428+
allow_empty: bool = ...
414429
def __init__(
415430
self,
416431
choices: Sequence[Any],
@@ -423,7 +438,7 @@ class MultipleChoiceField(ChoiceField):
423438
required: bool = ...,
424439
default: Any = ...,
425440
initial: Any = ...,
426-
source: Union[Callable, str] = ...,
441+
source: Optional[str] = ...,
427442
label: Optional[str] = ...,
428443
help_text: str = ...,
429444
allow_null: bool = ...,
@@ -446,7 +461,7 @@ class FilePathField(ChoiceField):
446461
required: Optional[bool] = ...,
447462
default: Any = ...,
448463
initial: Any = ...,
449-
source: Union[Callable, str] = ...,
464+
source: Optional[str] = ...,
450465
label: Optional[str] = ...,
451466
help_text: str = ...,
452467
allow_null: bool = ...,
@@ -468,7 +483,7 @@ class FileField(Field):
468483
required: bool = ...,
469484
default: Any = ...,
470485
initial: Any = ...,
471-
source: Union[Callable, str] = ...,
486+
source: Optional[str] = ...,
472487
label: Optional[str] = ...,
473488
help_text: str = ...,
474489
allow_null: bool = ...,
@@ -482,6 +497,7 @@ class SupportsToPython(Protocol):
482497

483498
class ImageField(FileField):
484499
_DjangoImageField: SupportsToPython
500+
allow_empty: bool = ...
485501
def __init__(
486502
self,
487503
_DjangoImageField: Type[SupportsToPython] = ...,
@@ -493,7 +509,7 @@ class ImageField(FileField):
493509
required: bool = ...,
494510
default: Any = ...,
495511
initial: Any = ...,
496-
source: Union[Callable, str] = ...,
512+
source: Optional[str] = ...,
497513
label: Optional[str] = ...,
498514
help_text: str = ...,
499515
allow_null: bool = ...,
@@ -520,7 +536,7 @@ class ListField(Field):
520536
required: bool = ...,
521537
default: Any = ...,
522538
initial: Any = ...,
523-
source: Union[Callable, str] = ...,
539+
source: Optional[str] = ...,
524540
label: Optional[str] = ...,
525541
help_text: str = ...,
526542
allow_null: bool = ...,
@@ -540,7 +556,7 @@ class DictField(Field):
540556
required: bool = ...,
541557
default: Any = ...,
542558
initial: Any = ...,
543-
source: Union[Callable, str] = ...,
559+
source: Optional[str] = ...,
544560
label: Optional[str] = ...,
545561
help_text: str = ...,
546562
allow_null: bool = ...,
@@ -562,7 +578,7 @@ class JSONField(Field):
562578
required: bool = ...,
563579
default: Any = ...,
564580
initial: Any = ...,
565-
source: Union[Callable, str] = ...,
581+
source: Optional[str] = ...,
566582
label: Optional[str] = ...,
567583
help_text: str = ...,
568584
allow_null: bool = ...,
@@ -584,7 +600,7 @@ class SerializerMethodField(Field):
584600
required: bool = ...,
585601
default: Any = ...,
586602
initial: Any = ...,
587-
source: Union[Callable, str] = ...,
603+
source: Optional[str] = ...,
588604
label: Optional[str] = ...,
589605
help_text: str = ...,
590606
allow_null: bool = ...,
@@ -604,7 +620,7 @@ class ModelField(Field):
604620
required: bool = ...,
605621
default: Any = ...,
606622
initial: Any = ...,
607-
source: Union[Callable, str] = ...,
623+
source: Optional[str] = ...,
608624
label: Optional[str] = ...,
609625
help_text: str = ...,
610626
allow_null: bool = ...,

rest_framework-stubs/relations.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class ManyRelatedField(Field):
9191
default_empty_html: List[object] = ...
9292
html_cutoff: Optional[int] = ...
9393
html_cutoff_text: Optional[str] = ...
94+
child_relation: RelatedField = ...
95+
allow_empty: bool = ...
9496
def __init__(self, child_relation: Optional[RelatedField] = ..., *args: Any, **kwargs: Any) -> None: ...
9597
def get_choices(self, cutoff: Optional[int] = ...) -> _Choices: ...
9698
@property

0 commit comments

Comments
 (0)