Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed May 28, 2024
1 parent 40e0a36 commit 126664a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
14 changes: 12 additions & 2 deletions django-stubs/views/decorators/__init__.pyi
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]],
)
8 changes: 4 additions & 4 deletions django-stubs/views/decorators/debug.pyi
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]: ...
28 changes: 28 additions & 0 deletions tests/assert_type/views/decorators/test_csrf.py
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()
15 changes: 0 additions & 15 deletions tests/typecheck/views/decorators/test_csrf.yml

This file was deleted.

0 comments on commit 126664a

Please sign in to comment.