Skip to content

Commit b7854f0

Browse files
authored
Add missing None return to __init__ methods (#492)
Seemed a bit inconsistent. This has no effect on user code.
1 parent c06c06a commit b7854f0

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

rest_framework-stubs/fields.pyi

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class Field(Generic[_VT, _DT, _RP, _IN]):
101101
error_messages: dict[str, StrOrPromise] = ...,
102102
validators: Sequence[Validator[_VT]] | None = ...,
103103
allow_null: bool = ...,
104-
): ...
104+
) -> None: ...
105105
def bind(self, field_name: str, parent: BaseSerializer) -> None: ...
106106
@property
107107
def validators(self) -> list[Validator[_VT]]: ...
@@ -173,7 +173,7 @@ class CharField(Field[str, str, str, Any]):
173173
trim_whitespace: bool = ...,
174174
max_length: int = ...,
175175
min_length: int | None = ...,
176-
): ...
176+
) -> None: ...
177177

178178
class EmailField(CharField): ...
179179

@@ -198,7 +198,7 @@ class RegexField(CharField):
198198
trim_whitespace: bool = ...,
199199
max_length: int = ...,
200200
min_length: int | None = ...,
201-
): ...
201+
) -> None: ...
202202

203203
class SlugField(CharField):
204204
allow_unicode: bool
@@ -222,7 +222,7 @@ class SlugField(CharField):
222222
trim_whitespace: bool = ...,
223223
max_length: int = ...,
224224
min_length: int | None = ...,
225-
): ...
225+
) -> None: ...
226226

227227
class URLField(CharField): ...
228228

@@ -245,7 +245,7 @@ class UUIDField(Field[uuid.UUID, uuid.UUID | str | int, str, Any]):
245245
error_messages: dict[str, StrOrPromise] = ...,
246246
validators: Sequence[Validator[uuid.UUID]] | None = ...,
247247
allow_null: bool = ...,
248-
): ...
248+
) -> None: ...
249249

250250
class IPAddressField(CharField):
251251
protocol: str
@@ -270,7 +270,7 @@ class IPAddressField(CharField):
270270
trim_whitespace: bool = ...,
271271
max_length: int = ...,
272272
min_length: int | None = ...,
273-
): ...
273+
) -> None: ...
274274

275275
class IntegerField(Field[int, float | int | str, int, Any]):
276276
MAX_STRING_LENGTH: int
@@ -294,7 +294,7 @@ class IntegerField(Field[int, float | int | str, int, Any]):
294294
error_messages: dict[str, StrOrPromise] = ...,
295295
validators: Sequence[Validator[int]] | None = ...,
296296
allow_null: bool = ...,
297-
): ...
297+
) -> None: ...
298298

299299
class FloatField(Field[float, float | int | str, str, Any]):
300300
MAX_STRING_LENGTH: int
@@ -318,7 +318,7 @@ class FloatField(Field[float, float | int | str, str, Any]):
318318
error_messages: dict[str, StrOrPromise] = ...,
319319
validators: Sequence[Validator[float]] | None = ...,
320320
allow_null: bool = ...,
321-
): ...
321+
) -> None: ...
322322

323323
class DecimalField(Field[Decimal, int | float | str | Decimal, str, Any]):
324324
MAX_STRING_LENGTH: int
@@ -353,7 +353,7 @@ class DecimalField(Field[Decimal, int | float | str | Decimal, str, Any]):
353353
error_messages: dict[str, StrOrPromise] = ...,
354354
validators: Sequence[Validator[Decimal]] | None = ...,
355355
allow_null: bool = ...,
356-
): ...
356+
) -> None: ...
357357
def validate_precision(self, value: Decimal) -> Decimal: ...
358358
def quantize(self, value: Decimal) -> Decimal: ...
359359

@@ -379,7 +379,7 @@ class DateTimeField(Field[datetime.datetime, datetime.datetime | str, str, Any])
379379
error_messages: dict[str, StrOrPromise] = ...,
380380
validators: Sequence[Validator[datetime.datetime]] | None = ...,
381381
allow_null: bool = ...,
382-
): ...
382+
) -> None: ...
383383
def enforce_timezone(self, value: datetime.datetime) -> datetime.datetime: ...
384384
def default_timezone(self) -> str | None: ...
385385

@@ -403,7 +403,7 @@ class DateField(Field[datetime.date, datetime.date | str, str, Any]):
403403
error_messages: dict[str, StrOrPromise] = ...,
404404
validators: Sequence[Validator[datetime.date]] | None = ...,
405405
allow_null: bool = ...,
406-
): ...
406+
) -> None: ...
407407

408408
class TimeField(Field[datetime.time, datetime.time | str, str, Any]):
409409
datetime_parser: Callable[[str, str], datetime.datetime]
@@ -425,7 +425,7 @@ class TimeField(Field[datetime.time, datetime.time | str, str, Any]):
425425
error_messages: dict[str, StrOrPromise] = ...,
426426
validators: Sequence[Validator[datetime.time]] | None = ...,
427427
allow_null: bool = ...,
428-
): ...
428+
) -> None: ...
429429

430430
class DurationField(Field[datetime.timedelta, datetime.timedelta | str, str, Any]):
431431
max_value: datetime.timedelta | None
@@ -447,7 +447,7 @@ class DurationField(Field[datetime.timedelta, datetime.timedelta | str, str, Any
447447
error_messages: dict[str, StrOrPromise] = ...,
448448
validators: Sequence[Validator[datetime.timedelta]] | None = ...,
449449
allow_null: bool = ...,
450-
): ...
450+
) -> None: ...
451451

452452
class ChoiceField(Field[str, str | int | tuple[str | int, str | int | tuple], str, Any]):
453453
html_cutoff: int | None
@@ -475,7 +475,7 @@ class ChoiceField(Field[str, str | int | tuple[str | int, str | int | tuple], st
475475
html_cutoff: int = ...,
476476
html_cutoff_text: StrOrPromise = ...,
477477
allow_blank: bool = ...,
478-
): ...
478+
) -> None: ...
479479
def iter_options(self) -> Iterable[Option]: ...
480480
def _get_choices(self) -> dict[Any, Any]: ...
481481
def _set_choices(self, choices: Iterable[Any]) -> None: ...
@@ -510,7 +510,7 @@ class MultipleChoiceField(
510510
html_cutoff_text: StrOrPromise = ...,
511511
allow_blank: bool = ...,
512512
allow_empty: bool = ...,
513-
): ...
513+
) -> None: ...
514514

515515
class FilePathField(ChoiceField):
516516
def __init__(
@@ -535,7 +535,7 @@ class FilePathField(ChoiceField):
535535
html_cutoff: int = ...,
536536
html_cutoff_text: StrOrPromise = ...,
537537
allow_blank: bool = ...,
538-
): ...
538+
) -> None: ...
539539

540540
class FileField(Field[File, File, str | None, Any]): # this field can return None without raising!
541541
max_length: int
@@ -559,7 +559,7 @@ class FileField(Field[File, File, str | None, Any]): # this field can return No
559559
max_length: int = ...,
560560
allow_empty_file: bool = ...,
561561
use_url: bool = ...,
562-
): ...
562+
) -> None: ...
563563

564564
class ImageField(FileField):
565565
_DjangoImageField: SupportsToPython
@@ -582,7 +582,7 @@ class ImageField(FileField):
582582
allow_empty_file: bool = ...,
583583
use_url: bool = ...,
584584
_DjangoImageField: type[SupportsToPython] = ...,
585-
): ...
585+
) -> None: ...
586586

587587
class _UnvalidatedField(Field): ...
588588

@@ -610,7 +610,7 @@ class ListField(Field[list[Any], list[Any], list[Any], Any]):
610610
allow_empty: bool = ...,
611611
max_length: int = ...,
612612
min_length: int = ...,
613-
): ...
613+
) -> None: ...
614614
def run_child_validation(self, data: list[Mapping[Any, Any]]) -> Any: ...
615615

616616
class DictField(Field[dict[Any, Any], dict[Any, Any], dict[Any, Any], Any]):
@@ -633,7 +633,7 @@ class DictField(Field[dict[Any, Any], dict[Any, Any], dict[Any, Any], Any]):
633633
*,
634634
child: Field = ...,
635635
allow_empty: bool = ...,
636-
): ...
636+
) -> None: ...
637637
def run_child_validation(self, data: Any) -> Any: ...
638638

639639
class HStoreField(DictField):
@@ -661,7 +661,7 @@ class JSONField(Field[dict[str, Any] | list[dict[str, Any]], dict[str, Any] | li
661661
binary: bool = ...,
662662
encoder: type[JSONEncoder] | None = ...,
663663
decoder: type[JSONDecoder] | None = ...,
664-
): ...
664+
) -> None: ...
665665

666666
class ReadOnlyField(Field): ...
667667
class HiddenField(Field): ...
@@ -684,7 +684,7 @@ class SerializerMethodField(Field):
684684
error_messages: dict[str, StrOrPromise] = ...,
685685
validators: Sequence[Validator[Any]] | None = ...,
686686
allow_null: bool = ...,
687-
): ...
687+
) -> None: ...
688688

689689
class ModelField(Field):
690690
model_field: models.Field
@@ -706,4 +706,4 @@ class ModelField(Field):
706706
validators: Sequence[Validator[Any]] | None = ...,
707707
allow_null: bool = ...,
708708
max_length: int = ...,
709-
): ...
709+
) -> None: ...

rest_framework-stubs/relations.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class RelatedField(Generic[_MT, _DT, _PT], Field[_MT, _DT, _PT, Any]):
5454
validators: Sequence[Validator[_MT]] | None = ...,
5555
error_messages: dict[str, StrOrPromise] | None = ...,
5656
style: dict[str, str] | None = ...,
57-
): ...
57+
) -> None: ...
5858
# mypy doesn't accept the typing below, although its accurate to what this class is doing, hence the ignore
5959
def __new__(cls, *args: Any, **kwargs: Any) -> RelatedField[_MT, _DT, _PT] | ManyRelatedField: ... # type: ignore
6060
@classmethod
@@ -94,7 +94,7 @@ class PrimaryKeyRelatedField(RelatedField[_MT, _MT, Any]):
9494
error_messages: dict[str, StrOrPromise] | None = ...,
9595
style: dict[str, str] | None = ...,
9696
pk_field: str | Field | None = ...,
97-
): ...
97+
) -> None: ...
9898

9999
class HyperlinkedRelatedField(RelatedField[_MT, str, Hyperlink]):
100100
reverse: Callable
@@ -125,7 +125,7 @@ class HyperlinkedRelatedField(RelatedField[_MT, str, Hyperlink]):
125125
lookup_field: str | None = ...,
126126
lookup_url_kwarg: str | None = ...,
127127
format: str | None = ...,
128-
): ...
128+
) -> None: ...
129129
def get_object(self, view_name: str, *view_args: Any, **view_kwargs: Any) -> _MT: ...
130130
def get_url(self, obj: Model, view_name: str, request: Request, format: str | None) -> str | None: ...
131131

@@ -153,7 +153,7 @@ class SlugRelatedField(RelatedField[_MT, str, str]):
153153
error_messages: dict[str, StrOrPromise] | None = ...,
154154
style: dict[str, str] | None = ...,
155155
slug_field: str | None = ...,
156-
): ...
156+
) -> None: ...
157157
def to_internal_value(self, data: Any) -> _MT: ...
158158
def to_representation(self, value: _MT) -> str: ...
159159

@@ -179,7 +179,7 @@ class ManyRelatedField(Field[Sequence[Any], Sequence[Any], list[Any], Any]):
179179
allow_null: bool = ...,
180180
allow_empty: bool = ...,
181181
child_relation: RelatedField = ...,
182-
): ...
182+
) -> None: ...
183183
def get_value(self, dictionary: Mapping[Any, Any]) -> list[Any]: ...
184184
def get_choices(self, cutoff: int | None = ...) -> dict: ...
185185
@property

rest_framework-stubs/response.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Response(SimpleTemplateResponse):
2121
headers: Mapping[str, str] | None = ...,
2222
exception: bool = ...,
2323
content_type: str | None = ...,
24-
): ...
24+
) -> None: ...
2525
@property
2626
def rendered_content(self) -> Any: ...
2727
def render(self) -> Any: ...

rest_framework-stubs/serializers.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class BaseSerializer(Generic[_IN], Field[Any, Any, Any, _IN]):
9999
error_messages: dict[str, StrOrPromise] = ...,
100100
validators: Sequence[Validator[Any]] | None = ...,
101101
allow_null: bool = ...,
102-
): ...
102+
) -> None: ...
103103
@classmethod
104104
def many_init(cls, *args: Any, **kwargs: Any) -> BaseSerializer: ...
105105
def is_valid(self, raise_exception: bool = ...) -> bool: ...
@@ -173,7 +173,7 @@ class ListSerializer(
173173
allow_null: bool = ...,
174174
min_length: int | None = ...,
175175
max_length: int | None = ...,
176-
): ...
176+
) -> None: ...
177177
def get_initial(self) -> list[Mapping[Any, Any]]: ...
178178
def validate(self, attrs: Any) -> Any: ...
179179
@property
@@ -219,7 +219,7 @@ class ModelSerializer(Serializer, BaseSerializer[_MT]):
219219
validators: Sequence[Validator[_MT]] | None = ...,
220220
allow_null: bool = ...,
221221
allow_empty: bool = ...,
222-
): ...
222+
) -> None: ...
223223
def update(self, instance: _MT, validated_data: Any) -> _MT: ...
224224
def create(self, validated_data: Any) -> _MT: ...
225225
def save(self, **kwargs: Any) -> _MT: ...

rest_framework-stubs/settings.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class APISettings:
6565
user_settings: DefaultsSettings | None = ...,
6666
defaults: DefaultsSettings | None = ...,
6767
import_strings: Sequence[str] | None = ...,
68-
): ...
68+
) -> None: ...
6969
@property
7070
def user_settings(self) -> Mapping[str, Any]: ...
7171
def __getattr__(self, attr: str) -> Any: ...

0 commit comments

Comments
 (0)