Skip to content

Fix type of data parameter in get test requests #267

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

Merged
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions rest_framework-stubs/test.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Iterable, Mapping
from typing import Any

import coreapi
Expand All @@ -13,6 +14,13 @@ from django.test.client import RequestFactory as DjangoRequestFactory
from rest_framework.authtoken.models import Token
from rest_framework.request import Request
from rest_framework.response import _MonkeyPatchedResponse
from typing_extensions import TypeAlias

_GetDataType: TypeAlias = (
Mapping[str, str | bytes | int | Iterable[str | bytes | int]]
| Iterable[tuple[str, str | bytes | int | Iterable[str | bytes | int]]]
| None
)

def force_authenticate(
request: HttpRequest, user: AnonymousUser | AbstractBaseUser | None = ..., token: Token | None = ...
Expand Down Expand Up @@ -50,7 +58,7 @@ class APIRequestFactory(DjangoRequestFactory):
renderer_classes: Any
def __init__(self, enforce_csrf_checks: bool = ..., **defaults: Any) -> None: ...
def request(self, **kwargs: Any) -> Request: ... # type: ignore[override]
def get(self, path: str, data: dict[str, Any] | str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
def get(self, path: str, data: _GetDataType = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
def post(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
def put(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
def patch(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> Request: ... # type: ignore[override]
Expand All @@ -68,7 +76,7 @@ class APIClient(APIRequestFactory, DjangoClient):
def credentials(self, **kwargs: Any): ...
def force_authenticate(self, user: AnonymousUser | AbstractBaseUser = ..., token: Token | None = ...) -> None: ...
def request(self, **kwargs: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def get(self, path: str, data: dict[str, Any] | str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def get(self, path: str, data: _GetDataType = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def post(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def put(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
def patch(self, path: str, data: Any | None = ..., format: str | None = ..., content_type: str | None = ..., follow: bool = ..., **extra: Any) -> _MonkeyPatchedResponse: ... # type: ignore[override]
Expand Down
6 changes: 6 additions & 0 deletions scripts/typecheck_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
'expected "Iterable[Any]"',
'Value of type variable "_MT" of "paginate_queryset" of "CursorPagination" cannot be "object"',
'Value of type "Union[object, Any]" is not indexable',
'Argument 2 to "get" of "APIRequestFactory" has incompatible type "Dict[str, object]"',
],
"test_parsers.py": ['"object" has no attribute', 'Argument 1 to "isnan" has incompatible type'],
"test_permissions.py": [
Expand Down Expand Up @@ -243,6 +244,11 @@
],
"test_viewsets.py": [
'(expression has type "None", variable has type "Request")',
'Argument 2 to "get" of "APIRequestFactory" has incompatible type "str"',
"note: Following member(s) of ",
"note: Expected:",
"note: Got:",
"note: def ",
],
"utils.py": ['Invalid signature "Callable[[BadType], Any]"'],
}
Expand Down