Skip to content

Commit 496b117

Browse files
authored
Improve GenericAPIView.serializer_class classvar type generics (#672)
The type for the attribute does not match what the `get_serializer_class` function returns. Thus, modifying it to match so it is `type[BaseSerializer[_MT_co]]` Unfortunately this doesn't solve the issue of projects programmatically returning different serializers in `get_serializer_class` such that one option would be: `return self.serializer_class` such that it would be technically incompatible with the typing. But that seems outside the scope of this change and there are other ways to accomplish it (e.g. holding known serializer classes in a `dict` on the class as an attribute).
1 parent dcfb120 commit 496b117

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

rest_framework-stubs/generics.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BaseFilterProtocol(Protocol[_MT_inv]):
3333

3434
class GenericAPIView(views.APIView, UsesQuerySet[_MT_co]):
3535
queryset: QuerySet[_MT_co] | Manager[_MT_co] | None
36-
serializer_class: type[BaseSerializer] | None
36+
serializer_class: type[BaseSerializer[_MT_co]] | None
3737
lookup_field: str
3838
lookup_url_kwarg: str | None
3939
filter_backends: Sequence[type[BaseFilterBackend | BaseFilterProtocol[_MT_co]]]

0 commit comments

Comments
 (0)