diff --git a/rest_framework-stubs/relations.pyi b/rest_framework-stubs/relations.pyi index cf86940f..a77a472a 100644 --- a/rest_framework-stubs/relations.pyi +++ b/rest_framework-stubs/relations.pyi @@ -31,18 +31,18 @@ _MT = TypeVar("_MT", bound=Model) _DT = TypeVar("_DT") # Data Type _PT = TypeVar("_PT") # Primitive Type -class RelatedField(Field[_MT, _DT, _PT, Any]): +class RelatedField(Field[_MT, Any, _PT, Any]): queryset: QuerySet[_MT] | Manager[_MT] | None html_cutoff: int | None html_cutoff_text: str | None def __init__( self, *, - many: bool = ..., - allow_empty: bool = ..., queryset: QuerySet[_MT] | Manager[_MT] | None = ..., html_cutoff: int | None = ..., html_cutoff_text: str = ..., + many: bool = ..., + allow_empty: bool = ..., read_only: bool = ..., write_only: bool = ..., required: bool | None = None, @@ -51,29 +51,29 @@ class RelatedField(Field[_MT, _DT, _PT, Any]): source: str | None = None, label: StrOrPromise | None = ..., help_text: StrOrPromise | None = None, - allow_null: bool = ..., - validators: Sequence[Validator[_MT]] | None = ..., - error_messages: dict[str, StrOrPromise] | None = ..., style: dict[str, str] | None = ..., + error_messages: dict[str, StrOrPromise] | None = ..., + validators: Sequence[Validator[_MT]] | None = ..., + allow_null: bool = ..., ) -> None: ... # mypy doesn't accept the typing below, although its accurate to what this class is doing, hence the ignore - def __new__(cls, *args: Any, **kwargs: Any) -> RelatedField[_MT, _DT, _PT] | ManyRelatedField: ... # type: ignore + def __new__(cls, *args: Any, **kwargs: Any) -> RelatedField[_MT, _PT] | ManyRelatedField: ... # type: ignore @classmethod def many_init(cls, *args: Any, **kwargs: Any) -> ManyRelatedField: ... def get_queryset(self) -> QuerySet[_MT]: ... def use_pk_only_optimization(self) -> bool: ... + def get_attribute(self, instance: _MT) -> _PT | None: ... def get_choices(self, cutoff: int | None = ...) -> dict: ... @property def choices(self) -> dict: ... @property def grouped_choices(self) -> dict: ... def iter_options(self) -> Iterable[Option]: ... - def get_attribute(self, instance: _MT) -> _PT | None: ... def display_value(self, instance: _MT) -> str: ... -class StringRelatedField(RelatedField[_MT, _MT, str]): ... +class StringRelatedField(RelatedField[Any, str]): ... -class PrimaryKeyRelatedField(RelatedField[_MT, _MT, Any]): +class PrimaryKeyRelatedField(RelatedField[Any, Any]): pk_field: str | None def __init__( self, @@ -98,7 +98,7 @@ class PrimaryKeyRelatedField(RelatedField[_MT, _MT, Any]): pk_field: str | Field | None = ..., ) -> None: ... -class HyperlinkedRelatedField(RelatedField[_MT, str, Hyperlink]): +class HyperlinkedRelatedField(RelatedField[Any, Hyperlink]): reverse: Callable lookup_field: str lookup_url_kwarg: str @@ -129,12 +129,12 @@ class HyperlinkedRelatedField(RelatedField[_MT, str, Hyperlink]): lookup_url_kwarg: str | None = ..., format: str | None = ..., ) -> None: ... - def get_object(self, view_name: str, view_args: list[Any], view_kwargs: dict[str, Any]) -> _MT: ... + def get_object(self, view_name: str, view_args: list[Any], view_kwargs: dict[str, Any]) -> Any: ... def get_url(self, obj: Model, view_name: str, request: Request, format: str | None) -> str | None: ... class HyperlinkedIdentityField(HyperlinkedRelatedField): ... -class SlugRelatedField(RelatedField[_MT, str, str]): +class SlugRelatedField(RelatedField[Any, str]): slug_field: str | None def __init__( self, @@ -158,7 +158,7 @@ class SlugRelatedField(RelatedField[_MT, str, str]): error_messages: dict[str, StrOrPromise] | None = ..., style: dict[str, str] | None = ..., ) -> None: ... - def to_internal_value(self, data: Any) -> _MT: ... + def to_internal_value(self, data: Any) -> Any: ... def to_representation(self, value: _MT) -> str: ... class ManyRelatedField(Field[Sequence[Any], Sequence[Any], list[Any], Any]):