When using validators in serializers, mypy raises an error
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
validators = [
serializers.UniqueTogetherValidator(
queryset=User.objects.all(),
fields=["username"],
),
serializers.UniqueForDateValidator(
queryset=User.objects.all(),
field="email",
date_field="date_joined",
),
]
error: Module "rest_framework.serializers" does not explicitly export attribute "UniqueTogetherValidator" [attr-defined]
error: Module has no attribute "UniqueForDateValidator" [attr-defined]
Modules and variables imported into the stub are not considered exported from the stub unless the import uses the import ... as ... form or the equivalent from ... import ... as ... form.
The modules needs to be explicitly exported and the exports should be aligned with rest_framework/serielizers
from rest_framework.validators import UniqueTogetherValidator as UniqueTogetherValidator
Bug report
What's wrong
When using validators in serializers, mypy raises an error
How is that should be
According to PEP-484 Stub Files
The modules needs to be explicitly exported and the exports should be aligned with rest_framework/serielizers
I'll happily open a PR in a bit
System information
python
version: 3.11django
version: 4.2.7mypy
version: 1.10.0django-stubs
version: 4.2.7