mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-22 03:41:28 +08:00
* proper redirect return type annotations made with Literal * Mapping instead of Dict type annotation for context in render() with test * removed Union and Context * typo Co-authored-by: Kacper Szmigiel <szmigielkacper@gmai.com> Add __init__ to OrderedSet (#381) Issue 382 (#384) * WIP fix, pushed for testing * added _ prefix for internal types Co-authored-by: Kacper Szmigiel <szmigielkacper@gmai.com> Fix parameter types for assertJSONEqual/NotEqual (#385) Add get_supported_language_variant (#386) Issue 309 (#383) * added tags for user models * type test for HttpRequest.user * test for User and AnonymousUser tags * httrequest test fix * checking python version fix for readibility * Rewrite version check for readability * Annotate is_authenticated/is_anonymous with Literal-type * Add auth in INSTALLED_APPS in test * Fix wrong type assertion in test * Fix misconception of how branch-testing works * Remove user from WSGIRequest * Change HttpRequest-transformer to set user-type to include AnonymousUser * Add check for anonymous_user_info=None to appease mypy * Isort transformers/request * Remove trailing whitespace * Remove unused import Co-authored-by: Kacper Szmigiel <szmigielkacper@gmai.com> * fix formatting and unused import * reformatted again Co-authored-by: Kacper Szmigiel <szmigielkacper@gmai.com>
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
import sys
|
|
from typing import Any, Callable, List, Mapping, Optional, overload, Protocol, Sequence, Type, TypeVar, Union
|
|
|
|
from django.db.models.base import Model
|
|
from django.http.response import (
|
|
HttpResponse as HttpResponse,
|
|
HttpResponseRedirect as HttpResponseRedirect,
|
|
HttpResponsePermanentRedirect as HttpResponsePermanentRedirect,
|
|
)
|
|
|
|
from django.db.models import Manager, QuerySet
|
|
from django.http import HttpRequest
|
|
|
|
if sys.version_info < (3, 8):
|
|
from typing_extensions import Literal
|
|
else:
|
|
from typing import Literal
|
|
|
|
def render_to_response(
|
|
template_name: Union[str, Sequence[str]],
|
|
context: Optional[Mapping[str, Any]] = ...,
|
|
content_type: Optional[str] = ...,
|
|
status: Optional[int] = ...,
|
|
using: Optional[str] = ...,
|
|
) -> HttpResponse: ...
|
|
def render(
|
|
request: HttpRequest,
|
|
template_name: Union[str, Sequence[str]],
|
|
context: Optional[Mapping[str, Any]] = ...,
|
|
content_type: Optional[str] = ...,
|
|
status: Optional[int] = ...,
|
|
using: Optional[str] = ...,
|
|
) -> HttpResponse: ...
|
|
|
|
class SupportsGetAbsoluteUrl(Protocol): ...
|
|
|
|
@overload
|
|
def redirect(
|
|
to: Union[Callable, str, SupportsGetAbsoluteUrl], *args: Any, permanent: Literal[True], **kwargs: Any
|
|
) -> HttpResponsePermanentRedirect: ...
|
|
@overload
|
|
def redirect(
|
|
to: Union[Callable, str, SupportsGetAbsoluteUrl], *args: Any, permanent: Literal[False], **kwargs: Any
|
|
) -> HttpResponseRedirect: ...
|
|
@overload
|
|
def redirect(
|
|
to: Union[Callable, str, SupportsGetAbsoluteUrl], *args: Any, permanent: bool = ..., **kwargs: Any
|
|
) -> Union[HttpResponseRedirect, HttpResponsePermanentRedirect]: ...
|
|
|
|
_T = TypeVar("_T", bound=Model)
|
|
|
|
def get_object_or_404(klass: Union[Type[_T], Manager[_T], QuerySet[_T]], *args: Any, **kwargs: Any) -> _T: ...
|
|
def get_list_or_404(klass: Union[Type[_T], Manager[_T], QuerySet[_T]], *args: Any, **kwargs: Any) -> List[_T]: ...
|
|
def resolve_url(to: Union[Callable, Model, str], *args: Any, **kwargs: Any) -> str: ...
|