-
-
Notifications
You must be signed in to change notification settings - Fork 131
Closed
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
We currently end up having to add e.g. assert isinstance(instance, SomeModel)
to update methods. I think it would make sense for ModelSerializer
to be defined as approximately:
M = TypeVar("M", bound=Model)
class ModelSerializer(Serializer, Generic[M]):
class Meta:
model: ClassVar[M]
def update(self, instance: M, validated_data: Any) -> M:
...
When we narrow the instance
argument to update()
ourselves, we violate LSP because update()
is defined in BaseSerializer
and instance
need to accept any Model
. I think it would be better if that LSP violation was moved into djangorestframework-stubs to paint over the upstream design decision and keeping it from leaking into "user space".
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed