From b7854f0847eaa271d1970e7b04ba4e6cea5778d7 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Wed, 18 Oct 2023 14:10:22 +0300 Subject: [PATCH] Add missing None return to __init__ methods (#492) Seemed a bit inconsistent. This has no effect on user code. --- rest_framework-stubs/fields.pyi | 46 ++++++++++++++-------------- rest_framework-stubs/relations.pyi | 10 +++--- rest_framework-stubs/response.pyi | 2 +- rest_framework-stubs/serializers.pyi | 6 ++-- rest_framework-stubs/settings.pyi | 2 +- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/rest_framework-stubs/fields.pyi b/rest_framework-stubs/fields.pyi index 8bbedcb9f..d940c7195 100644 --- a/rest_framework-stubs/fields.pyi +++ b/rest_framework-stubs/fields.pyi @@ -101,7 +101,7 @@ class Field(Generic[_VT, _DT, _RP, _IN]): error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[_VT]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... def bind(self, field_name: str, parent: BaseSerializer) -> None: ... @property def validators(self) -> list[Validator[_VT]]: ... @@ -173,7 +173,7 @@ class CharField(Field[str, str, str, Any]): trim_whitespace: bool = ..., max_length: int = ..., min_length: int | None = ..., - ): ... + ) -> None: ... class EmailField(CharField): ... @@ -198,7 +198,7 @@ class RegexField(CharField): trim_whitespace: bool = ..., max_length: int = ..., min_length: int | None = ..., - ): ... + ) -> None: ... class SlugField(CharField): allow_unicode: bool @@ -222,7 +222,7 @@ class SlugField(CharField): trim_whitespace: bool = ..., max_length: int = ..., min_length: int | None = ..., - ): ... + ) -> None: ... class URLField(CharField): ... @@ -245,7 +245,7 @@ class UUIDField(Field[uuid.UUID, uuid.UUID | str | int, str, Any]): error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[uuid.UUID]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... class IPAddressField(CharField): protocol: str @@ -270,7 +270,7 @@ class IPAddressField(CharField): trim_whitespace: bool = ..., max_length: int = ..., min_length: int | None = ..., - ): ... + ) -> None: ... class IntegerField(Field[int, float | int | str, int, Any]): MAX_STRING_LENGTH: int @@ -294,7 +294,7 @@ class IntegerField(Field[int, float | int | str, int, Any]): error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[int]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... class FloatField(Field[float, float | int | str, str, Any]): MAX_STRING_LENGTH: int @@ -318,7 +318,7 @@ class FloatField(Field[float, float | int | str, str, Any]): error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[float]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... class DecimalField(Field[Decimal, int | float | str | Decimal, str, Any]): MAX_STRING_LENGTH: int @@ -353,7 +353,7 @@ class DecimalField(Field[Decimal, int | float | str | Decimal, str, Any]): error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[Decimal]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... def validate_precision(self, value: Decimal) -> Decimal: ... def quantize(self, value: Decimal) -> Decimal: ... @@ -379,7 +379,7 @@ class DateTimeField(Field[datetime.datetime, datetime.datetime | str, str, Any]) error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[datetime.datetime]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... def enforce_timezone(self, value: datetime.datetime) -> datetime.datetime: ... def default_timezone(self) -> str | None: ... @@ -403,7 +403,7 @@ class DateField(Field[datetime.date, datetime.date | str, str, Any]): error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[datetime.date]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... class TimeField(Field[datetime.time, datetime.time | str, str, Any]): datetime_parser: Callable[[str, str], datetime.datetime] @@ -425,7 +425,7 @@ class TimeField(Field[datetime.time, datetime.time | str, str, Any]): error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[datetime.time]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... class DurationField(Field[datetime.timedelta, datetime.timedelta | str, str, Any]): max_value: datetime.timedelta | None @@ -447,7 +447,7 @@ class DurationField(Field[datetime.timedelta, datetime.timedelta | str, str, Any error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[datetime.timedelta]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... class ChoiceField(Field[str, str | int | tuple[str | int, str | int | tuple], str, Any]): html_cutoff: int | None @@ -475,7 +475,7 @@ class ChoiceField(Field[str, str | int | tuple[str | int, str | int | tuple], st html_cutoff: int = ..., html_cutoff_text: StrOrPromise = ..., allow_blank: bool = ..., - ): ... + ) -> None: ... def iter_options(self) -> Iterable[Option]: ... def _get_choices(self) -> dict[Any, Any]: ... def _set_choices(self, choices: Iterable[Any]) -> None: ... @@ -510,7 +510,7 @@ class MultipleChoiceField( html_cutoff_text: StrOrPromise = ..., allow_blank: bool = ..., allow_empty: bool = ..., - ): ... + ) -> None: ... class FilePathField(ChoiceField): def __init__( @@ -535,7 +535,7 @@ class FilePathField(ChoiceField): html_cutoff: int = ..., html_cutoff_text: StrOrPromise = ..., allow_blank: bool = ..., - ): ... + ) -> None: ... class FileField(Field[File, File, str | None, Any]): # this field can return None without raising! max_length: int @@ -559,7 +559,7 @@ class FileField(Field[File, File, str | None, Any]): # this field can return No max_length: int = ..., allow_empty_file: bool = ..., use_url: bool = ..., - ): ... + ) -> None: ... class ImageField(FileField): _DjangoImageField: SupportsToPython @@ -582,7 +582,7 @@ class ImageField(FileField): allow_empty_file: bool = ..., use_url: bool = ..., _DjangoImageField: type[SupportsToPython] = ..., - ): ... + ) -> None: ... class _UnvalidatedField(Field): ... @@ -610,7 +610,7 @@ class ListField(Field[list[Any], list[Any], list[Any], Any]): allow_empty: bool = ..., max_length: int = ..., min_length: int = ..., - ): ... + ) -> None: ... def run_child_validation(self, data: list[Mapping[Any, Any]]) -> Any: ... 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]): *, child: Field = ..., allow_empty: bool = ..., - ): ... + ) -> None: ... def run_child_validation(self, data: Any) -> Any: ... class HStoreField(DictField): @@ -661,7 +661,7 @@ class JSONField(Field[dict[str, Any] | list[dict[str, Any]], dict[str, Any] | li binary: bool = ..., encoder: type[JSONEncoder] | None = ..., decoder: type[JSONDecoder] | None = ..., - ): ... + ) -> None: ... class ReadOnlyField(Field): ... class HiddenField(Field): ... @@ -684,7 +684,7 @@ class SerializerMethodField(Field): error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[Any]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... class ModelField(Field): model_field: models.Field @@ -706,4 +706,4 @@ class ModelField(Field): validators: Sequence[Validator[Any]] | None = ..., allow_null: bool = ..., max_length: int = ..., - ): ... + ) -> None: ... diff --git a/rest_framework-stubs/relations.pyi b/rest_framework-stubs/relations.pyi index 07f7de078..7f7e1a03c 100644 --- a/rest_framework-stubs/relations.pyi +++ b/rest_framework-stubs/relations.pyi @@ -54,7 +54,7 @@ class RelatedField(Generic[_MT, _DT, _PT], Field[_MT, _DT, _PT, Any]): validators: Sequence[Validator[_MT]] | None = ..., error_messages: dict[str, StrOrPromise] | None = ..., style: dict[str, str] | None = ..., - ): ... + ) -> None: ... # mypy doesn't accept the typing below, although its accurate to what this class is doing, hence the ignore def __new__(cls, *args: Any, **kwargs: Any) -> RelatedField[_MT, _DT, _PT] | ManyRelatedField: ... # type: ignore @classmethod @@ -94,7 +94,7 @@ class PrimaryKeyRelatedField(RelatedField[_MT, _MT, Any]): error_messages: dict[str, StrOrPromise] | None = ..., style: dict[str, str] | None = ..., pk_field: str | Field | None = ..., - ): ... + ) -> None: ... class HyperlinkedRelatedField(RelatedField[_MT, str, Hyperlink]): reverse: Callable @@ -125,7 +125,7 @@ class HyperlinkedRelatedField(RelatedField[_MT, str, Hyperlink]): lookup_field: str | None = ..., lookup_url_kwarg: str | None = ..., format: str | None = ..., - ): ... + ) -> None: ... def get_object(self, view_name: str, *view_args: Any, **view_kwargs: Any) -> _MT: ... def get_url(self, obj: Model, view_name: str, request: Request, format: str | None) -> str | None: ... @@ -153,7 +153,7 @@ class SlugRelatedField(RelatedField[_MT, str, str]): error_messages: dict[str, StrOrPromise] | None = ..., style: dict[str, str] | None = ..., slug_field: str | None = ..., - ): ... + ) -> None: ... def to_internal_value(self, data: Any) -> _MT: ... def to_representation(self, value: _MT) -> str: ... @@ -179,7 +179,7 @@ class ManyRelatedField(Field[Sequence[Any], Sequence[Any], list[Any], Any]): allow_null: bool = ..., allow_empty: bool = ..., child_relation: RelatedField = ..., - ): ... + ) -> None: ... def get_value(self, dictionary: Mapping[Any, Any]) -> list[Any]: ... def get_choices(self, cutoff: int | None = ...) -> dict: ... @property diff --git a/rest_framework-stubs/response.pyi b/rest_framework-stubs/response.pyi index 7652d3a11..ddee9af47 100644 --- a/rest_framework-stubs/response.pyi +++ b/rest_framework-stubs/response.pyi @@ -21,7 +21,7 @@ class Response(SimpleTemplateResponse): headers: Mapping[str, str] | None = ..., exception: bool = ..., content_type: str | None = ..., - ): ... + ) -> None: ... @property def rendered_content(self) -> Any: ... def render(self) -> Any: ... diff --git a/rest_framework-stubs/serializers.pyi b/rest_framework-stubs/serializers.pyi index 7b198820b..d2bbf6764 100644 --- a/rest_framework-stubs/serializers.pyi +++ b/rest_framework-stubs/serializers.pyi @@ -99,7 +99,7 @@ class BaseSerializer(Generic[_IN], Field[Any, Any, Any, _IN]): error_messages: dict[str, StrOrPromise] = ..., validators: Sequence[Validator[Any]] | None = ..., allow_null: bool = ..., - ): ... + ) -> None: ... @classmethod def many_init(cls, *args: Any, **kwargs: Any) -> BaseSerializer: ... def is_valid(self, raise_exception: bool = ...) -> bool: ... @@ -173,7 +173,7 @@ class ListSerializer( allow_null: bool = ..., min_length: int | None = ..., max_length: int | None = ..., - ): ... + ) -> None: ... def get_initial(self) -> list[Mapping[Any, Any]]: ... def validate(self, attrs: Any) -> Any: ... @property @@ -219,7 +219,7 @@ class ModelSerializer(Serializer, BaseSerializer[_MT]): validators: Sequence[Validator[_MT]] | None = ..., allow_null: bool = ..., allow_empty: bool = ..., - ): ... + ) -> None: ... def update(self, instance: _MT, validated_data: Any) -> _MT: ... def create(self, validated_data: Any) -> _MT: ... def save(self, **kwargs: Any) -> _MT: ... diff --git a/rest_framework-stubs/settings.pyi b/rest_framework-stubs/settings.pyi index a508b5b5b..176e186b3 100644 --- a/rest_framework-stubs/settings.pyi +++ b/rest_framework-stubs/settings.pyi @@ -65,7 +65,7 @@ class APISettings: user_settings: DefaultsSettings | None = ..., defaults: DefaultsSettings | None = ..., import_strings: Sequence[str] | None = ..., - ): ... + ) -> None: ... @property def user_settings(self) -> Mapping[str, Any]: ... def __getattr__(self, attr: str) -> Any: ...