-
-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
from collections.abc import Awaitable, Callable | ||
from typing import TypeVar | ||
|
||
from django.utils.deprecation import _AsyncGetResponseCallable, _GetResponseCallable | ||
from django.http.request import HttpRequest | ||
from django.http.response import HttpResponseBase | ||
from typing_extensions import Concatenate | ||
|
||
_ViewFuncT = TypeVar("_ViewFuncT", bound=_AsyncGetResponseCallable | _GetResponseCallable) # noqa: PYI018 | ||
# Examples: | ||
# def (request: HttpRequest, path_param: str) -> HttpResponseBase | ||
# async def (request: HttpRequest) -> HttpResponseBase | ||
_ViewFuncT = TypeVar( # noqa: PYI018 | ||
"_ViewFuncT", | ||
bound=Callable[Concatenate[HttpRequest, ...], HttpResponseBase] | ||
| Callable[Concatenate[HttpRequest, ...], Awaitable[HttpResponseBase]], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from collections.abc import Callable | ||
from typing import Literal | ||
from typing import Any, Literal, TypeVar | ||
|
||
from . import _ViewFuncT | ||
_F = TypeVar("_F", bound=Callable[..., Any]) | ||
|
||
coroutine_functions_to_sensitive_variables: dict[int, Literal["__ALL__"] | tuple[str, ...]] | ||
|
||
def sensitive_variables(*variables: str) -> Callable[[_ViewFuncT], _ViewFuncT]: ... | ||
def sensitive_post_parameters(*parameters: str) -> Callable[[_ViewFuncT], _ViewFuncT]: ... | ||
def sensitive_variables(*variables: str) -> Callable[[_F], _F]: ... | ||
def sensitive_post_parameters(*parameters: str) -> Callable[[_F], _F]: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.http.request import HttpRequest | ||
from django.http.response import HttpResponse | ||
from django.views.decorators.csrf import csrf_protect | ||
|
||
|
||
@csrf_protect | ||
def good_view(request: HttpRequest) -> HttpResponse: | ||
return HttpResponse() | ||
|
||
|
||
@csrf_protect | ||
async def good_async_view(request: HttpRequest) -> HttpResponse: | ||
return HttpResponse() | ||
|
||
|
||
@csrf_protect | ||
def good_view_with_arguments(request: HttpRequest, other: int, args: str) -> HttpResponse: | ||
return HttpResponse() | ||
|
||
|
||
@csrf_protect # type: ignore # pyright: ignore | ||
def bad_view(request: int) -> str: | ||
return "" | ||
|
||
|
||
@csrf_protect # type: ignore # pyright: ignore | ||
def bad_view_no_arguments() -> HttpResponse: | ||
return HttpResponse() |
This file was deleted.
Oops, something went wrong.