From 68df52259a4d9a8aeeeccc088947b27d0667e04b Mon Sep 17 00:00:00 2001 From: SKairinos Date: Thu, 7 Nov 2024 14:37:30 +0000 Subject: [PATCH] AnyBaseModelViewSet --- codeforlife/serializers/model_list.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/codeforlife/serializers/model_list.py b/codeforlife/serializers/model_list.py index 18249ad..99be97a 100644 --- a/codeforlife/serializers/model_list.py +++ b/codeforlife/serializers/model_list.py @@ -21,8 +21,12 @@ from ..views import BaseModelViewSet, ModelViewSet RequestUser = t.TypeVar("RequestUser", bound=User) + AnyBaseModelViewSet = t.TypeVar( + "AnyBaseModelViewSet", bound=BaseModelViewSet + ) else: RequestUser = t.TypeVar("RequestUser") + AnyBaseModelViewSet = t.TypeVar("AnyBaseModelViewSet") AnyModel = t.TypeVar("AnyModel", bound=Model) AnyBaseRequest = t.TypeVar("AnyBaseRequest", bound=BaseRequest) @@ -36,7 +40,7 @@ class BaseModelListSerializer( BaseSerializer[AnyBaseRequest], _ListSerializer[t.List[AnyModel]], - t.Generic[AnyBaseRequest, AnyModel], + t.Generic[AnyBaseRequest, AnyBaseModelViewSet, AnyModel], ): """Base model list serializer for all model list serializers. @@ -57,7 +61,7 @@ class Meta: instance: t.Optional[t.List[AnyModel]] batch_size: t.Optional[int] = None - view: "BaseModelViewSet[AnyBaseRequest, AnyModel]" + view: AnyBaseModelViewSet @property def non_none_instance(self): @@ -185,7 +189,11 @@ def to_representation(self, instance: t.List[AnyModel]) -> t.List[DataDict]: class ModelListSerializer( - BaseModelListSerializer[Request[RequestUser], AnyModel], + BaseModelListSerializer[ + Request[RequestUser], + "ModelViewSet[RequestUser, AnyModel]", + AnyModel, + ], t.Generic[RequestUser, AnyModel], ): """Base model list serializer for all model list serializers. @@ -204,5 +212,3 @@ class Meta: model = User list_serializer_class = UserListSerializer """ - - view: "ModelViewSet[RequestUser, AnyModel]" # type: ignore[assignment]