From 62c21a533d74bd8a943400a77612c8a8e2e69e24 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Mon, 23 Oct 2023 01:50:46 +0300 Subject: [PATCH] Fix Field constructor argument None'ability * Also relation field `source=` was typed to accept `Callable | str`, but callable was never allowed. It may be the *name* of a method as string. --- rest_framework-stubs/fields.pyi | 298 +++++++++++++-------------- rest_framework-stubs/relations.pyi | 28 +-- rest_framework-stubs/serializers.pyi | 36 ++-- scripts/stubtest/allowlist.txt | 8 + scripts/stubtest/allowlist_todo.txt | 12 -- 5 files changed, 189 insertions(+), 193 deletions(-) diff --git a/rest_framework-stubs/fields.pyi b/rest_framework-stubs/fields.pyi index fb6a2540c..af001f788 100644 --- a/rest_framework-stubs/fields.pyi +++ b/rest_framework-stubs/fields.pyi @@ -92,14 +92,14 @@ class Field(Generic[_VT, _DT, _RP, _IN]): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[_VT] = ..., initial: _DefaultInitial[_VT] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[_VT]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -160,14 +160,14 @@ class CharField(Field[str, str, str, Any]): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[StrOrPromise] = ..., initial: _DefaultInitial[str] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[str]] | None = ..., allow_null: bool = ..., allow_blank: bool = ..., @@ -185,14 +185,14 @@ class RegexField(CharField): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[StrOrPromise] = ..., initial: _DefaultInitial[str] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[str]] | None = ..., allow_null: bool = ..., allow_blank: bool = ..., @@ -209,14 +209,14 @@ class SlugField(CharField): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[StrOrPromise] = ..., initial: _DefaultInitial[str] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[str]] | None = ..., allow_null: bool = ..., allow_blank: bool = ..., @@ -236,14 +236,14 @@ class UUIDField(Field[uuid.UUID, uuid.UUID | str | int, str, Any]): format: str | None = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[uuid.UUID] = ..., initial: _DefaultInitial[uuid.UUID] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[uuid.UUID]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -257,14 +257,14 @@ class IPAddressField(CharField): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[str] = ..., initial: _DefaultInitial[str] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[str]] | None = ..., allow_null: bool = ..., allow_blank: bool = ..., @@ -285,14 +285,14 @@ class IntegerField(Field[int, float | int | str, int, Any]): min_value: int = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[int] = ..., initial: _DefaultInitial[int] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[int]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -309,14 +309,14 @@ class FloatField(Field[float, float | int | str, str, Any]): min_value: float = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[float] = ..., initial: _DefaultInitial[float] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[float]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -335,22 +335,22 @@ class DecimalField(Field[Decimal, int | float | str | Decimal, str, Any]): self, max_digits: int | None, decimal_places: int | None, - coerce_to_string: bool = ..., - max_value: Decimal | int | float = ..., - min_value: Decimal | int | float = ..., + coerce_to_string: bool | None = None, + max_value: Decimal | int | float | None = None, + min_value: Decimal | int | float | None = None, localize: bool = ..., - rounding: str | None = ..., + rounding: str | None = None, *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[Decimal] = ..., initial: _DefaultInitial[Decimal] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[Decimal]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -364,20 +364,20 @@ class DateTimeField(Field[datetime.datetime, datetime.datetime | str, str, Any]) timezone: datetime.tzinfo def __init__( self, - format: str | None = ..., - input_formats: Sequence[str] = ..., + format: str | None | _Empty = ..., + input_formats: Sequence[str] | None = None, default_timezone: datetime.tzinfo | None = ..., *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[datetime.datetime] = ..., initial: _DefaultInitial[datetime.datetime] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[datetime.datetime]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -390,19 +390,19 @@ class DateField(Field[datetime.date, datetime.date | str, str, Any]): input_formats: Sequence[str] def __init__( self, - format: str | None = ..., - input_formats: Sequence[str] = ..., + format: str | None | _Empty = ..., + input_formats: Sequence[str] | None = None, *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[datetime.date] = ..., initial: _DefaultInitial[datetime.date] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[datetime.date]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -413,19 +413,19 @@ class TimeField(Field[datetime.time, datetime.time | str, str, Any]): input_formats: Sequence[str] def __init__( self, - format: str | None = ..., - input_formats: Sequence[str] = ..., + format: str | None | _Empty = ..., + input_formats: Sequence[str] | None = None, *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[datetime.time] = ..., initial: _DefaultInitial[datetime.time] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[datetime.time]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -440,14 +440,14 @@ class DurationField(Field[datetime.timedelta, datetime.timedelta | str, str, Any min_value: datetime.timedelta | int | float = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[datetime.timedelta] = ..., initial: _DefaultInitial[datetime.timedelta] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[datetime.timedelta]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -465,14 +465,14 @@ class ChoiceField(Field[str, str | int | tuple[str | int, str | int | tuple], st *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[StrOrPromise | int] = ..., initial: _DefaultInitial[str | int] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[Any]] | None = ..., allow_null: bool = ..., html_cutoff: int = ..., @@ -500,14 +500,14 @@ class MultipleChoiceField( choices: Iterable[Any], read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[set[str | int] | set[str] | set[int]] = ..., initial: _DefaultInitial[set[StrOrPromise | int] | set[StrOrPromise] | set[int]] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[Any]] | None = ..., allow_null: bool = ..., html_cutoff: int = ..., @@ -520,21 +520,21 @@ class FilePathField(ChoiceField): def __init__( self, path: str, - match: str = ..., + match: str | None = None, recursive: bool = ..., allow_files: bool = ..., allow_folders: bool = ..., - required: bool = ..., + required: bool | None = None, *, read_only: bool = ..., write_only: bool = ..., default: _DefaultInitial[str] = ..., initial: _DefaultInitial[str] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[Any]] | None = ..., allow_null: bool = ..., html_cutoff: int = ..., @@ -551,14 +551,14 @@ class FileField(Field[File, File, str | None, Any]): # this field can return No *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[File] = ..., initial: _DefaultInitial[File] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[File]] | None = ..., allow_null: bool = ..., max_length: int = ..., @@ -573,14 +573,14 @@ class ImageField(FileField): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[File] = ..., initial: _DefaultInitial[File] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[File]] | None = ..., allow_null: bool = ..., max_length: int = ..., @@ -601,14 +601,14 @@ class ListField(Field[list[Any], list[Any], list[Any], Any]): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[list[Any]] = ..., initial: _DefaultInitial[list[Any]] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[list[Any]]] | None = ..., allow_null: bool = ..., child: Field = ..., @@ -626,14 +626,14 @@ class DictField(Field[dict[Any, Any], dict[Any, Any], dict[Any, Any], Any]): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[dict[Any, Any]] = ..., initial: _DefaultInitial[dict[Any, Any]] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[dict[Any, Any]]] | None = ..., allow_null: bool = ..., child: Field = ..., @@ -653,14 +653,14 @@ class JSONField(Field[dict[str, Any] | list[dict[str, Any]], dict[str, Any] | li *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DefaultInitial[Mapping[Any, Any]] = ..., initial: _DefaultInitial[Mapping[Any, Any]] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[Any]] | None = ..., allow_null: bool = ..., binary: bool = ..., @@ -679,14 +679,14 @@ class SerializerMethodField(Field): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: Any = ..., initial: Any = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[Any]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -700,14 +700,14 @@ class ModelField(Field): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: Any = ..., initial: Any = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[Any]] | None = ..., allow_null: bool = ..., max_length: int = ..., diff --git a/rest_framework-stubs/relations.pyi b/rest_framework-stubs/relations.pyi index 5208b4177..853b51128 100644 --- a/rest_framework-stubs/relations.pyi +++ b/rest_framework-stubs/relations.pyi @@ -45,12 +45,12 @@ class RelatedField(Generic[_MT, _DT, _PT], Field[_MT, _DT, _PT, Any]): html_cutoff_text: str = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: Any = ..., initial: Any = ..., - source: Callable | str = ..., + source: str | None = None, label: StrOrPromise | None = ..., - help_text: StrOrPromise = ..., + help_text: StrOrPromise | None = None, allow_null: bool = ..., validators: Sequence[Validator[_MT]] | None = ..., error_messages: dict[str, StrOrPromise] | None = ..., @@ -85,12 +85,12 @@ class PrimaryKeyRelatedField(RelatedField[_MT, _MT, Any]): html_cutoff_text: str = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: Any = ..., initial: Any = ..., - source: Callable | str = ..., + source: str | None = None, label: StrOrPromise | None = ..., - help_text: StrOrPromise = ..., + help_text: StrOrPromise | None = None, allow_null: bool = ..., validators: Sequence[Validator[_MT]] | None = ..., error_messages: dict[str, StrOrPromise] | None = ..., @@ -115,12 +115,12 @@ class HyperlinkedRelatedField(RelatedField[_MT, str, Hyperlink]): html_cutoff_text: str = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: Any = ..., initial: Any = ..., - source: Callable | str = ..., + source: str | None = None, label: StrOrPromise | None = ..., - help_text: StrOrPromise = ..., + help_text: StrOrPromise | None = None, allow_null: bool = ..., validators: Sequence[Validator[_MT]] | None = ..., error_messages: dict[str, StrOrPromise] | None = ..., @@ -147,12 +147,12 @@ class SlugRelatedField(RelatedField[_MT, str, str]): html_cutoff_text: str = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _DT = ..., initial: _MT | Callable[[Any], _MT] = ..., - source: Callable | str = ..., + source: str | None = None, label: StrOrPromise | None = ..., - help_text: StrOrPromise = ..., + help_text: StrOrPromise | None = None, allow_null: bool = ..., validators: Sequence[Validator[_MT]] | None = ..., error_messages: dict[str, StrOrPromise] | None = ..., @@ -173,10 +173,10 @@ class ManyRelatedField(Field[Sequence[Any], Sequence[Any], list[Any], Any]): *, read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: Sequence[Any] = ..., initial: Sequence[Any] | Callable[[Any], Sequence[Any]] = ..., - source: Callable | str = ..., + source: str | None = None, label: StrOrPromise | None = ..., help_text: str | None = ..., style: dict[str, str] | None = ..., diff --git a/rest_framework-stubs/serializers.pyi b/rest_framework-stubs/serializers.pyi index 7f51c268f..9c828f2d1 100644 --- a/rest_framework-stubs/serializers.pyi +++ b/rest_framework-stubs/serializers.pyi @@ -90,14 +90,14 @@ class BaseSerializer(Generic[_IN], Field[Any, Any, Any, _IN]): context: dict[str, Any] = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: Any = ..., initial: Any = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[Any]] | None = ..., allow_null: bool = ..., ) -> None: ... @@ -162,14 +162,14 @@ class ListSerializer( child: Field | BaseSerializer | None = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: Any = ..., initial: Any = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[list[Any]]] | None = ..., allow_null: bool = ..., min_length: int | None = ..., @@ -210,14 +210,14 @@ class ModelSerializer(Serializer, BaseSerializer[_MT]): context: dict[str, Any] = ..., read_only: bool = ..., write_only: bool = ..., - required: bool = ..., + required: bool | None = None, default: _MT | Sequence[_MT] | Callable[[], _MT | Sequence[_MT]] = ..., initial: _MT | Sequence[_MT] | Callable[[], _MT | Sequence[_MT]] = ..., - source: str = ..., - label: StrOrPromise = ..., - help_text: StrOrPromise = ..., - style: dict[str, Any] = ..., - error_messages: dict[str, StrOrPromise] = ..., + source: str | None = None, + label: StrOrPromise | None = None, + help_text: StrOrPromise | None = None, + style: dict[str, Any] | None = None, + error_messages: dict[str, StrOrPromise] | None = None, validators: Sequence[Validator[_MT]] | None = ..., allow_null: bool = ..., allow_empty: bool = ..., diff --git a/scripts/stubtest/allowlist.txt b/scripts/stubtest/allowlist.txt index 22a9d7c4c..cd9ff03e7 100644 --- a/scripts/stubtest/allowlist.txt +++ b/scripts/stubtest/allowlist.txt @@ -14,3 +14,11 @@ rest_framework.serializers.HyperlinkedIdentityField.__init__ rest_framework.serializers.HyperlinkedRelatedField.__init__ rest_framework.serializers.ManyRelatedField.__init__ rest_framework.serializers.SlugRelatedField.__init__ + +# Mypy doesn't like default value `empty` +rest_framework.fields.DateField.__init__ +rest_framework.fields.DateTimeField.__init__ +rest_framework.fields.TimeField.__init__ +rest_framework.serializers.DateField.__init__ +rest_framework.serializers.DateTimeField.__init__ +rest_framework.serializers.TimeField.__init__ diff --git a/scripts/stubtest/allowlist_todo.txt b/scripts/stubtest/allowlist_todo.txt index 042b848b7..8d7f7ae4c 100644 --- a/scripts/stubtest/allowlist_todo.txt +++ b/scripts/stubtest/allowlist_todo.txt @@ -41,15 +41,10 @@ rest_framework.documentation.get_schemajs_view rest_framework.documentation.include_docs_urls rest_framework.fields.BooleanField.initial rest_framework.fields.CharField.initial -rest_framework.fields.DateField.__init__ rest_framework.fields.DateField.to_internal_value -rest_framework.fields.DateTimeField.__init__ rest_framework.fields.DateTimeField.to_internal_value -rest_framework.fields.DecimalField.__init__ rest_framework.fields.DictField.initial rest_framework.fields.DurationField.to_internal_value -rest_framework.fields.Field.__init__ -rest_framework.fields.FilePathField.__init__ rest_framework.fields.ListField.initial rest_framework.fields.ListField.to_representation rest_framework.fields.ModelField.get_attribute @@ -58,7 +53,6 @@ rest_framework.fields.NullBooleanField rest_framework.fields.Option rest_framework.fields.REGEX_TYPE rest_framework.fields.SupportsToPython -rest_framework.fields.TimeField.__init__ rest_framework.fields.TimeField.to_internal_value rest_framework.fields.empty rest_framework.generics.BaseFilterProtocol @@ -112,15 +106,10 @@ rest_framework.serializers.AuthenticationFailed rest_framework.serializers.BaseSerializer.is_valid rest_framework.serializers.BooleanField.initial rest_framework.serializers.CharField.initial -rest_framework.serializers.DateField.__init__ rest_framework.serializers.DateField.to_internal_value -rest_framework.serializers.DateTimeField.__init__ rest_framework.serializers.DateTimeField.to_internal_value -rest_framework.serializers.DecimalField.__init__ rest_framework.serializers.DictField.initial rest_framework.serializers.DurationField.to_internal_value -rest_framework.serializers.Field.__init__ -rest_framework.serializers.FilePathField.__init__ rest_framework.serializers.HyperlinkedRelatedField.get_object rest_framework.serializers.ListField.initial rest_framework.serializers.ListField.to_representation @@ -140,7 +129,6 @@ rest_framework.serializers.ParseError rest_framework.serializers.PermissionDenied rest_framework.serializers.SlugRelatedField.to_representation rest_framework.serializers.Throttled -rest_framework.serializers.TimeField.__init__ rest_framework.serializers.TimeField.to_internal_value rest_framework.serializers.UnsupportedMediaType rest_framework.serializers.empty