From 952e1c3ee9b17f3340ae0e39788e590ab79c01cc Mon Sep 17 00:00:00 2001 From: Maciej Gol <1kroolik1@gmail.com> Date: Sat, 13 Apr 2019 21:31:49 +0200 Subject: [PATCH] Preserve callable type in view decorators (#67) --- django-stubs/views/decorators/cache.pyi | 6 ++++-- django-stubs/views/decorators/clickjacking.pyi | 10 ++++++---- django-stubs/views/decorators/csrf.pyi | 6 ++++-- django-stubs/views/decorators/gzip.pyi | 4 ++-- django-stubs/views/decorators/http.pyi | 8 +++++--- django-stubs/views/decorators/vary.pyi | 6 ++++-- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/django-stubs/views/decorators/cache.pyi b/django-stubs/views/decorators/cache.pyi index 5495929..992df85 100644 --- a/django-stubs/views/decorators/cache.pyi +++ b/django-stubs/views/decorators/cache.pyi @@ -1,5 +1,7 @@ -from typing import Any, Callable, Optional +from typing import Any, Callable, Optional, TypeVar + +_F = TypeVar("_F", bound=Callable[..., Any]) def cache_page(timeout: float, *, cache: Optional[Any] = ..., key_prefix: Optional[Any] = ...) -> Callable: ... def cache_control(**kwargs: Any) -> Callable: ... -def never_cache(view_func: Callable) -> Callable: ... +def never_cache(view_func: _F) -> _F: ... diff --git a/django-stubs/views/decorators/clickjacking.pyi b/django-stubs/views/decorators/clickjacking.pyi index 397c708..f93f1ff 100644 --- a/django-stubs/views/decorators/clickjacking.pyi +++ b/django-stubs/views/decorators/clickjacking.pyi @@ -1,5 +1,7 @@ -from typing import Callable +from typing import Callable, TypeVar, Any -def xframe_options_deny(view_func: Callable) -> Callable: ... -def xframe_options_sameorigin(view_func: Callable) -> Callable: ... -def xframe_options_exempt(view_func: Callable) -> Callable: ... +_F = TypeVar("_F", bound=Callable[..., Any]) + +def xframe_options_deny(view_func: _F) -> _F: ... +def xframe_options_sameorigin(view_func: _F) -> _F: ... +def xframe_options_exempt(view_func: _F) -> _F: ... diff --git a/django-stubs/views/decorators/csrf.pyi b/django-stubs/views/decorators/csrf.pyi index 333e9dd..a9f9a04 100644 --- a/django-stubs/views/decorators/csrf.pyi +++ b/django-stubs/views/decorators/csrf.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable +from typing import Any, Callable, TypeVar from django.middleware.csrf import CsrfViewMiddleware @@ -14,4 +14,6 @@ class _EnsureCsrfCookie(CsrfViewMiddleware): ensure_csrf_cookie: Any -def csrf_exempt(view_func: Callable) -> Callable: ... +_F = TypeVar("_F", bound=Callable[..., Any]) + +def csrf_exempt(view_func: _F) -> _F: ... diff --git a/django-stubs/views/decorators/gzip.pyi b/django-stubs/views/decorators/gzip.pyi index 1990839..7b3766c 100644 --- a/django-stubs/views/decorators/gzip.pyi +++ b/django-stubs/views/decorators/gzip.pyi @@ -1,5 +1,5 @@ -from typing import Callable, TypeVar +from typing import Callable, TypeVar, Any -_C = TypeVar("_C", bound=Callable) +_C = TypeVar("_C", bound=Callable[..., Any]) def gzip_page(view_func: _C) -> _C: ... diff --git a/django-stubs/views/decorators/http.pyi b/django-stubs/views/decorators/http.pyi index e4f096a..1829946 100644 --- a/django-stubs/views/decorators/http.pyi +++ b/django-stubs/views/decorators/http.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, List, Optional +from typing import Any, Callable, List, Optional, TypeVar conditional_page: Any @@ -8,6 +8,8 @@ require_GET: Any require_POST: Any require_safe: Any +_F = TypeVar("_F", bound=Callable[..., Any]) + def condition(etag_func: Optional[Callable] = ..., last_modified_func: Optional[Callable] = ...) -> Callable: ... -def etag(etag_func: Callable) -> Callable: ... -def last_modified(last_modified_func: Callable) -> Callable: ... +def etag(etag_func: Callable[..., Any]) -> Callable[[_F], _F]: ... +def last_modified(last_modified_func: Callable[..., Any]) -> Callable[[_F], _F]: ... diff --git a/django-stubs/views/decorators/vary.pyi b/django-stubs/views/decorators/vary.pyi index 45417b3..0601a4a 100644 --- a/django-stubs/views/decorators/vary.pyi +++ b/django-stubs/views/decorators/vary.pyi @@ -1,4 +1,6 @@ -from typing import Any, Callable +from typing import Any, Callable, TypeVar + +_F = TypeVar("_F", bound=Callable[..., Any]) def vary_on_headers(*headers: Any) -> Callable: ... -def vary_on_cookie(func: Callable) -> Callable: ... +def vary_on_cookie(func: _F) -> _F: ...