Skip to content

Commit 952e1c3

Browse files
maciej-golmkurnikov
authored andcommitted
Preserve callable type in view decorators (#67)
1 parent 5dd6ecc commit 952e1c3

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from typing import Any, Callable, Optional
1+
from typing import Any, Callable, Optional, TypeVar
2+
3+
_F = TypeVar("_F", bound=Callable[..., Any])
24

35
def cache_page(timeout: float, *, cache: Optional[Any] = ..., key_prefix: Optional[Any] = ...) -> Callable: ...
46
def cache_control(**kwargs: Any) -> Callable: ...
5-
def never_cache(view_func: Callable) -> Callable: ...
7+
def never_cache(view_func: _F) -> _F: ...
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from typing import Callable
1+
from typing import Callable, TypeVar, Any
22

3-
def xframe_options_deny(view_func: Callable) -> Callable: ...
4-
def xframe_options_sameorigin(view_func: Callable) -> Callable: ...
5-
def xframe_options_exempt(view_func: Callable) -> Callable: ...
3+
_F = TypeVar("_F", bound=Callable[..., Any])
4+
5+
def xframe_options_deny(view_func: _F) -> _F: ...
6+
def xframe_options_sameorigin(view_func: _F) -> _F: ...
7+
def xframe_options_exempt(view_func: _F) -> _F: ...

django-stubs/views/decorators/csrf.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Callable
1+
from typing import Any, Callable, TypeVar
22

33
from django.middleware.csrf import CsrfViewMiddleware
44

@@ -14,4 +14,6 @@ class _EnsureCsrfCookie(CsrfViewMiddleware):
1414

1515
ensure_csrf_cookie: Any
1616

17-
def csrf_exempt(view_func: Callable) -> Callable: ...
17+
_F = TypeVar("_F", bound=Callable[..., Any])
18+
19+
def csrf_exempt(view_func: _F) -> _F: ...
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from typing import Callable, TypeVar
1+
from typing import Callable, TypeVar, Any
22

3-
_C = TypeVar("_C", bound=Callable)
3+
_C = TypeVar("_C", bound=Callable[..., Any])
44

55
def gzip_page(view_func: _C) -> _C: ...
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Callable, List, Optional
1+
from typing import Any, Callable, List, Optional, TypeVar
22

33
conditional_page: Any
44

@@ -8,6 +8,8 @@ require_GET: Any
88
require_POST: Any
99
require_safe: Any
1010

11+
_F = TypeVar("_F", bound=Callable[..., Any])
12+
1113
def condition(etag_func: Optional[Callable] = ..., last_modified_func: Optional[Callable] = ...) -> Callable: ...
12-
def etag(etag_func: Callable) -> Callable: ...
13-
def last_modified(last_modified_func: Callable) -> Callable: ...
14+
def etag(etag_func: Callable[..., Any]) -> Callable[[_F], _F]: ...
15+
def last_modified(last_modified_func: Callable[..., Any]) -> Callable[[_F], _F]: ...
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Any, Callable
1+
from typing import Any, Callable, TypeVar
2+
3+
_F = TypeVar("_F", bound=Callable[..., Any])
24

35
def vary_on_headers(*headers: Any) -> Callable: ...
4-
def vary_on_cookie(func: Callable) -> Callable: ...
6+
def vary_on_cookie(func: _F) -> _F: ...

0 commit comments

Comments
 (0)