Skip to content

Commit 7840ec6

Browse files
authored
Improve BaseSerializer and ListSerializer method to_representation() (#509)
* Fix `BaseSerializer` and `ListSerializer` `to_representation()` return type * Fixed allowlist entry
1 parent 6af878b commit 7840ec6

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

rest_framework-stubs/serializers.pyi

+3-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class BaseSerializer(Generic[_IN], Field[Any, Any, Any, _IN]):
113113
def update(self, instance: _IN, validated_data: Any) -> _IN: ...
114114
def create(self, validated_data: Any) -> _IN: ...
115115
def save(self, **kwargs: Any) -> _IN: ...
116-
def to_representation(self, instance: _IN) -> dict[str, Any]: ...
116+
def to_representation(self, instance: _IN) -> Any: ...
117117

118118
class SerializerMetaclass(type):
119119
def __new__(cls, name: Any, bases: Any, attrs: Any) -> Incomplete: ...
@@ -132,6 +132,7 @@ class Serializer(
132132
@cached_property
133133
def fields(self) -> BindingDict: ...
134134
def get_fields(self) -> dict[str, Field]: ...
135+
def to_representation(self, instance: _IN) -> dict[str, Any]: ...
135136
def validate(self, attrs: Any) -> Any: ...
136137
def __iter__(self) -> Iterator[BoundField]: ...
137138
def __getitem__(self, key: str) -> BoundField: ...
@@ -175,6 +176,7 @@ class ListSerializer(
175176
min_length: int | None = ...,
176177
max_length: int | None = ...,
177178
) -> None: ...
179+
def to_representation(self, data: Manager[Any] | Iterable[Any]) -> list[Any]: ... # type: ignore[override]
178180
def get_initial(self) -> list[Mapping[Any, Any]]: ...
179181
def validate(self, attrs: Any) -> Any: ...
180182
@property

scripts/stubtest/allowlist_todo.txt

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ rest_framework.serializers.HyperlinkedRelatedField.get_object
9494
rest_framework.serializers.ListField.initial
9595
rest_framework.serializers.ListField.to_representation
9696
rest_framework.serializers.ListSerializer.is_valid
97-
rest_framework.serializers.ListSerializer.to_representation
9897
rest_framework.serializers.ManyRelatedField.initial
9998
rest_framework.serializers.ManyRelatedField.to_representation
10099
rest_framework.serializers.MethodNotAllowed

0 commit comments

Comments
 (0)