From 8f4200204a9697b4925c63d7d447ba1e63c869a0 Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Sat, 27 Aug 2022 13:14:08 -0400 Subject: [PATCH 1/2] Use inherited types from CsrfViewMiddleware. Signed-off-by: Zixuan James Li --- django-stubs/views/decorators/csrf.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/django-stubs/views/decorators/csrf.pyi b/django-stubs/views/decorators/csrf.pyi index a9f9a047b..94117e5a6 100644 --- a/django-stubs/views/decorators/csrf.pyi +++ b/django-stubs/views/decorators/csrf.pyi @@ -8,9 +8,7 @@ class _EnsureCsrfToken(CsrfViewMiddleware): ... requires_csrf_token: Any -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 From 5fb320dbd79b7e50fe9e7d17d0c888329480a167 Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Sat, 27 Aug 2022 13:14:38 -0400 Subject: [PATCH 2/2] 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 --- django-stubs/views/decorators/csrf.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/django-stubs/views/decorators/csrf.pyi b/django-stubs/views/decorators/csrf.pyi index 94117e5a6..c2b73de3c 100644 --- a/django-stubs/views/decorators/csrf.pyi +++ b/django-stubs/views/decorators/csrf.pyi @@ -2,15 +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): ... -ensure_csrf_cookie: Any +ensure_csrf_cookie: Callable[[_F], _F] _F = TypeVar("_F", bound=Callable[..., Any])