From 59f529a78869f1162ef83a9b95a6dde5deb094d3 Mon Sep 17 00:00:00 2001 From: Serhii Tereshchenko Date: Sat, 27 Apr 2024 12:03:02 +0300 Subject: [PATCH 1/4] chore: Ignore override --- rest_framework-stubs/test.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework-stubs/test.pyi b/rest_framework-stubs/test.pyi index 88695594a..f0177bbdc 100644 --- a/rest_framework-stubs/test.pyi +++ b/rest_framework-stubs/test.pyi @@ -127,7 +127,7 @@ class ForceAuthClientHandler(ClientHandler): def __init__(self, *args: Any, **kwargs: Any): ... def get_response(self, request: Request) -> Response: ... # type: ignore[override] -class APIClient(APIRequestFactory, DjangoClient): +class APIClient(APIRequestFactory, DjangoClient): # pyright: ignore[reportIncompatibleMethodOverride] handler: Any = ... def credentials(self, **kwargs: Any) -> Any: ... def force_authenticate(self, user: Any | None = ..., token: Token | None = ...) -> None: ... From cd8b71e411a5f1934892c5c88ba21f7dc0b638b7 Mon Sep 17 00:00:00 2001 From: Serhii Tereshchenko Date: Sat, 27 Apr 2024 12:05:48 +0300 Subject: [PATCH 2/4] fix(serializers): Use dict[str, Any] for validated_data --- rest_framework-stubs/serializers.pyi | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/rest_framework-stubs/serializers.pyi b/rest_framework-stubs/serializers.pyi index b3e0128e9..8d5854d76 100644 --- a/rest_framework-stubs/serializers.pyi +++ b/rest_framework-stubs/serializers.pyi @@ -112,9 +112,8 @@ class BaseSerializer(Field[Any, Any, Any, Any]): @property def data(self) -> Any: ... errors: Any - # TODO(sbdchd): figure out how hard it would be to make this return a dict[str, Any] @property - def validated_data(self) -> Any: ... + def validated_data(self) -> dict[str, Any]: ... def update(self, instance: Any, validated_data: Any) -> Any: ... def create(self, validated_data: Any) -> Any: ... def save(self, **kwargs: Any) -> Any: ... @@ -135,7 +134,7 @@ class Serializer(BaseSerializer, metaclass=SerializerMetaclass): def get_initial(self) -> Any: ... fields: Any def get_fields(self) -> dict[str, Field[Any, Any, Any, Any]]: ... - def validate(self, attrs: Any) -> Any: ... + def validate(self, attrs: dict[str, Any]) -> dict[str, Any]: ... def __iter__(self) -> Iterator[str]: ... def __getitem__(self, key: str) -> BoundField: ... def _read_only_defaults(self) -> dict[str, Any]: ... @@ -219,8 +218,8 @@ class ModelSerializer(Serializer, BaseSerializer): allow_null: bool = ..., allow_empty: bool = ..., ): ... - def update(self, instance: Any, validated_data: Any) -> Any: ... - def create(self, validated_data: Any) -> Any: ... + def update(self, instance: Any, validated_data: dict[str, Any]) -> Any: ... + def create(self, validated_data: dict[str, Any]) -> Any: ... def save(self, **kwargs: Any) -> Any: ... def to_representation(self, instance: Any) -> Any: ... def get_field_names( From fabcbade25c1c28777e4da6b68560168b6875230 Mon Sep 17 00:00:00 2001 From: Serhii Tereshchenko Date: Sat, 27 Apr 2024 20:34:12 +0300 Subject: [PATCH 3/4] fix: Include case for many=True --- rest_framework-stubs/serializers.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework-stubs/serializers.pyi b/rest_framework-stubs/serializers.pyi index 8d5854d76..ef5903f16 100644 --- a/rest_framework-stubs/serializers.pyi +++ b/rest_framework-stubs/serializers.pyi @@ -113,7 +113,7 @@ class BaseSerializer(Field[Any, Any, Any, Any]): def data(self) -> Any: ... errors: Any @property - def validated_data(self) -> dict[str, Any]: ... + def validated_data(self) -> dict[str, Any] | list[dict[str, Any]]: ... def update(self, instance: Any, validated_data: Any) -> Any: ... def create(self, validated_data: Any) -> Any: ... def save(self, **kwargs: Any) -> Any: ... From e9ffb2a5b368b0854cf215e992aa0b84417e450b Mon Sep 17 00:00:00 2001 From: Serhii Tereshchenko Date: Sun, 28 Apr 2024 08:59:54 +0300 Subject: [PATCH 4/4] chore: Revert some changes --- rest_framework-stubs/serializers.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework-stubs/serializers.pyi b/rest_framework-stubs/serializers.pyi index ef5903f16..13eb2c805 100644 --- a/rest_framework-stubs/serializers.pyi +++ b/rest_framework-stubs/serializers.pyi @@ -112,8 +112,9 @@ class BaseSerializer(Field[Any, Any, Any, Any]): @property def data(self) -> Any: ... errors: Any + # TODO(sbdchd): figure out how hard it would be to make this return a dict[str, Any] @property - def validated_data(self) -> dict[str, Any] | list[dict[str, Any]]: ... + def validated_data(self) -> Any: ... def update(self, instance: Any, validated_data: Any) -> Any: ... def create(self, validated_data: Any) -> Any: ... def save(self, **kwargs: Any) -> Any: ...