Skip to content

Commit 373b63c

Browse files
authored
[3.15] Add functions related to UniqueConstraint (#591)
* [3.15] Add functions related to UniqueConstraint * [3.15] Fix to the correct type
1 parent 6d69ba7 commit 373b63c

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

rest_framework-stubs/serializers.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class ModelSerializer(Serializer, BaseSerializer[_MT]):
253253
self, kwargs: MutableMapping[str, Any], extra_kwargs: MutableMapping[str, Any]
254254
) -> MutableMapping[str, Any]: ...
255255
def get_extra_kwargs(self) -> dict[str, Any]: ...
256+
def get_unique_together_constraints(self, model: _MT) -> Iterator[tuple[set[tuple[str, ...]], Manager[_MT]]]: ...
256257
def get_uniqueness_extra_kwargs(
257258
self, field_names: Iterable[str], declared_fields: Mapping[str, Field], extra_kwargs: dict[str, Any]
258259
) -> tuple[dict[str, Any], dict[str, HiddenField]]: ...

rest_framework-stubs/utils/field_mapping.pyi

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from _typeshed import Incomplete
22
from collections.abc import MutableMapping, Sequence
3-
from typing import Any, Generic, TypeVar
3+
from typing import Any, Generic, Iterator, TypeVar
44

55
from django.db import models
6+
from rest_framework.validators import UniqueValidator
67

78
NUMERIC_FIELD_TYPES: Sequence[type[models.Field]]
89

@@ -17,6 +18,7 @@ class ClassLookupDict(Generic[_K, _V]):
1718

1819
def needs_label(model_field: models.Field, field_name: str) -> bool: ...
1920
def get_detail_view_name(model: models.Model) -> str: ...
21+
def get_unique_validators(field_name: str, model_field: models.Field) -> Iterator[UniqueValidator]: ...
2022
def get_field_kwargs(field_name: str, model_field: models.Field) -> dict[str, Any]: ...
2123
def get_relation_kwargs(field_name: str, relation_info: Incomplete) -> dict[str, Any]: ...
2224
def get_nested_relation_kwargs(relation_info: Incomplete) -> dict[str, Any]: ...

scripts/stubtest/allowlist_todo.txt

-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,3 @@ rest_framework.validators.Validator
135135
rest_framework.views.APIView.metadata_class
136136
rest_framework.views.AsView
137137
rest_framework.views.GenericView
138-
139-
# Added in 3.15:
140-
rest_framework.serializers.ModelSerializer.get_unique_together_constraints
141-
rest_framework.utils.field_mapping.get_unique_validators

0 commit comments

Comments
 (0)