Enhance stubs for csrf decorators. (#1130)

* Use inherited types from CsrfViewMiddleware.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* 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 <p359101898@gmail.com>

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
PIG208
2022-08-27 13:29:30 -04:00
committed by GitHub
parent 8bd00ba25a
commit 11ded9deaf

View File

@@ -2,17 +2,15 @@ from typing import Any, Callable, TypeVar
from django.middleware.csrf import CsrfViewMiddleware
csrf_protect: Any
csrf_protect: Callable[[_F], _F]
class _EnsureCsrfToken(CsrfViewMiddleware): ...
requires_csrf_token: Any
requires_csrf_token: Callable[[_F], _F]
class _EnsureCsrfCookie(CsrfViewMiddleware):
get_response: None
def process_view(self, request: Any, callback: Any, callback_args: Any, callback_kwargs: Any): ...
class _EnsureCsrfCookie(CsrfViewMiddleware): ...
ensure_csrf_cookie: Any
ensure_csrf_cookie: Callable[[_F], _F]
_F = TypeVar("_F", bound=Callable[..., Any])