Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(relations): remove some typevars in favor of Any #608

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions rest_framework-stubs/relations.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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]):
Expand Down