Skip to content

Commit c88356b

Browse files
committed
Feedback
1 parent 40e0a36 commit c88356b

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed
+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
from collections.abc import Awaitable, Callable
12
from typing import TypeVar
23

3-
from django.utils.deprecation import _AsyncGetResponseCallable, _GetResponseCallable
4+
from django.http.request import HttpRequest
5+
from django.http.response import HttpResponseBase
6+
from typing_extensions import Concatenate
47

5-
_ViewFuncT = TypeVar("_ViewFuncT", bound=_AsyncGetResponseCallable | _GetResponseCallable) # noqa: PYI018
8+
# Examples:
9+
# def (request: HttpRequest, path_param: str) -> HttpResponseBase
10+
# async def (request: HttpRequest) -> HttpResponseBase
11+
_ViewFuncT = TypeVar( # noqa: PYI018
12+
"_ViewFuncT",
13+
bound=Callable[Concatenate[HttpRequest, ...], HttpResponseBase]
14+
| Callable[Concatenate[HttpRequest, ...], Awaitable[HttpResponseBase]],
15+
)
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from collections.abc import Callable
2-
from typing import Literal
2+
from typing import Any, Literal, TypeVar
33

4-
from . import _ViewFuncT
4+
_F = TypeVar("_F", bound=Callable[..., Any])
55

66
coroutine_functions_to_sensitive_variables: dict[int, Literal["__ALL__"] | tuple[str, ...]]
77

8-
def sensitive_variables(*variables: str) -> Callable[[_ViewFuncT], _ViewFuncT]: ...
9-
def sensitive_post_parameters(*parameters: str) -> Callable[[_ViewFuncT], _ViewFuncT]: ...
8+
def sensitive_variables(*variables: str) -> Callable[[_F], _F]: ...
9+
def sensitive_post_parameters(*parameters: str) -> Callable[[_F], _F]: ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from django.http.request import HttpRequest
2+
from django.http.response import HttpResponse
3+
from django.views.decorators.csrf import csrf_protect
4+
5+
6+
@csrf_protect
7+
def good_view(request: HttpRequest) -> HttpResponse:
8+
return HttpResponse()
9+
10+
11+
@csrf_protect
12+
def good_view_with_arguments(request: HttpRequest, other: int, args: str) -> HttpResponse:
13+
return HttpResponse()
14+
15+
16+
@csrf_protect # type: ignore # pyright: ignore
17+
def bad_view(request: int) -> str:
18+
return ""
19+
20+
21+
@csrf_protect # type: ignore # pyright: ignore
22+
def bad_view_no_arguments() -> HttpResponse:
23+
return HttpResponse()

tests/typecheck/views/decorators/test_csrf.yml

-15
This file was deleted.

0 commit comments

Comments
 (0)