Skip to content

Commit

Permalink
model serializer type arg
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Nov 7, 2024
1 parent f092832 commit b7e603e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions codeforlife/views/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from ..user.models import User

RequestUser = t.TypeVar("RequestUser", bound=User)
AnyBaseModelSerializer = t.TypeVar(
"AnyBaseModelSerializer", bound=BaseModelSerializer
)

# NOTE: This raises an error during runtime.
# pylint: disable-next=too-few-public-methods
Expand All @@ -39,6 +42,7 @@ class _ModelViewSet(DrfModelViewSet[AnyModel], t.Generic[AnyModel]):

else:
RequestUser = t.TypeVar("RequestUser")
AnyBaseModelSerializer = t.TypeVar("AnyBaseModelSerializer")

# pylint: disable-next=too-many-ancestors
class _ModelViewSet(DrfModelViewSet, t.Generic[AnyModel]):
Expand All @@ -54,13 +58,11 @@ class _ModelViewSet(DrfModelViewSet, t.Generic[AnyModel]):
class BaseModelViewSet(
BaseAPIView[AnyBaseRequest],
_ModelViewSet[AnyModel],
t.Generic[AnyBaseRequest, AnyModel],
t.Generic[AnyBaseRequest, AnyBaseModelSerializer, AnyModel],
):
"""Base model view set for all model view sets."""

serializer_class: t.Optional[
t.Type["BaseModelSerializer[AnyBaseRequest, AnyModel]"]
]
serializer_class: t.Optional[t.Type[AnyBaseModelSerializer]]

@classmethod
def get_model_class(cls) -> t.Type[AnyModel]:
Expand Down Expand Up @@ -160,16 +162,16 @@ def partial_update( # type: ignore[override] # pragma: no cover

# pylint: disable-next=too-many-ancestors
class ModelViewSet(
BaseModelViewSet[Request[RequestUser], AnyModel],
BaseModelViewSet[
Request[RequestUser],
"ModelSerializer[RequestUser, AnyModel]",
AnyModel,
],
APIView[RequestUser],
t.Generic[RequestUser, AnyModel],
):
"""Base model view set for all model view sets."""

serializer_class: t.Optional[
t.Type["ModelSerializer[RequestUser, AnyModel]"]
]

def get_bulk_queryset(self, lookup_values: t.Collection):
"""Get the queryset for a bulk action.
Expand Down

0 comments on commit b7e603e

Please sign in to comment.