mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-08 04:54:48 +08:00
By declaring return type as -> Callable[[_C], _C], Mypy can infer that the decorated function has also the same arguments and return type as the original. View functions are constrained to return HttpResponseBase (or any subclass of it). Also added typecheck test coverage to most of the cases.
22 lines
982 B
Python
22 lines
982 B
Python
from typing import Callable, List, Optional, Set, Union, TypeVar, overload
|
|
|
|
from django.contrib.auth import REDIRECT_FIELD_NAME as REDIRECT_FIELD_NAME # noqa: F401
|
|
from django.http.response import HttpResponseBase
|
|
|
|
from django.contrib.auth.models import AbstractUser
|
|
|
|
_VIEW = TypeVar("_VIEW", bound=Callable[..., HttpResponseBase])
|
|
|
|
def user_passes_test(
|
|
test_func: Callable[[AbstractUser], bool], login_url: Optional[str] = ..., redirect_field_name: str = ...
|
|
) -> Callable[[_VIEW], _VIEW]: ...
|
|
|
|
# There are two ways of calling @login_required: @with(arguments) and @bare
|
|
@overload
|
|
def login_required(redirect_field_name: str = ..., login_url: Optional[str] = ...) -> Callable[[_VIEW], _VIEW]: ...
|
|
@overload
|
|
def login_required(function: _VIEW, redirect_field_name: str = ..., login_url: Optional[str] = ...) -> _VIEW: ...
|
|
def permission_required(
|
|
perm: Union[List[str], Set[str], str], login_url: None = ..., raise_exception: bool = ...
|
|
) -> Callable[[_VIEW], _VIEW]: ...
|