Skip to content

Commit 11ded9d

Browse files
authored
Enhance stubs for csrf decorators. (#1130)
* Use inherited types from CsrfViewMiddleware. Signed-off-by: Zixuan James Li <[email protected]> * Define decorators generated from middleware with TypeVars. csrf_protect and etc. are created via the decorator_from_middleware helper, which doesn't modify the original signature of the wrapped view function. Using TypeVar helps preserve the original type of the decorated callable. Signed-off-by: Zixuan James Li <[email protected]> Signed-off-by: Zixuan James Li <[email protected]>
1 parent 8bd00ba commit 11ded9d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Diff for: django-stubs/views/decorators/csrf.pyi

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ from typing import Any, Callable, TypeVar
22

33
from django.middleware.csrf import CsrfViewMiddleware
44

5-
csrf_protect: Any
5+
csrf_protect: Callable[[_F], _F]
66

77
class _EnsureCsrfToken(CsrfViewMiddleware): ...
88

9-
requires_csrf_token: Any
9+
requires_csrf_token: Callable[[_F], _F]
1010

11-
class _EnsureCsrfCookie(CsrfViewMiddleware):
12-
get_response: None
13-
def process_view(self, request: Any, callback: Any, callback_args: Any, callback_kwargs: Any): ...
11+
class _EnsureCsrfCookie(CsrfViewMiddleware): ...
1412

15-
ensure_csrf_cookie: Any
13+
ensure_csrf_cookie: Callable[[_F], _F]
1614

1715
_F = TypeVar("_F", bound=Callable[..., Any])
1816

0 commit comments

Comments
 (0)