typeddjango / djangorestframework-stubs

PEP-484 stubs for django-rest-framework
MIT License
421 stars 113 forks source link

Serializer.validators type does not include Unique... validators #555

Open mschoettle opened 3 months ago

mschoettle commented 3 months ago

Bug report

What's wrong

The Serializer.validatorsproperty has the type

Type of "self.validators" is "list[((Any) -> None) | ContextValidator[Any]]"

This is the result of reveal_type(self.validators) on an instance of ModelSerializer. I don't see it explicitly defined in serializers.pyi so I am not sure where exactly it is coming from.

When evaluating the elements of the list against UniqueTogetherValidator mypy reports that the condition always returns False.

None of the Unique... validators are a type that is mentioned above so that is my assumption why that is.

How is that should be

The type for the validators property should include the Unique... validators (at least for ModelSerializer).

System information

Napparific commented 3 months ago

I have encountered the same issue!