From d29dacd64b722d94a8fc9b38ea93ed4f48c6f710 Mon Sep 17 00:00:00 2001 From: snmishra Date: Sun, 25 Jul 2021 10:53:37 -0500 Subject: [PATCH] Add accepts method stub in HttpRequest (#676) * Add accepts method to HttpRequest stubs The accepts method (and dependencies) was missing in the stub for HttpRequest * Change accepted_types to return correct type * Fix Black formatting * Add annotation for MediaType __init__ args --- django-stubs/http/request.pyi | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/django-stubs/http/request.pyi b/django-stubs/http/request.pyi index d620f90..aff69ed 100644 --- a/django-stubs/http/request.pyi +++ b/django-stubs/http/request.pyi @@ -70,7 +70,8 @@ class HttpRequest(BytesIO): def scheme(self) -> Optional[str]: ... def is_secure(self) -> bool: ... def is_ajax(self) -> bool: ... - def accepted_types(self) -> str: ... + @property + def accepted_types(self) -> List[MediaType]: ... def __repr__(self) -> str: ... def parse_file_upload( self, META: Mapping[str, Any], post_data: BinaryIO @@ -80,6 +81,7 @@ class HttpRequest(BytesIO): @property def body(self) -> bytes: ... def _load_post_and_files(self) -> None: ... + def accepts(self, media_type: str) -> bool: ... _Q = TypeVar("_Q", bound="QueryDict") @@ -102,6 +104,12 @@ class QueryDict(MultiValueDict[str, str]): encoding: Optional[str] = ..., ) -> _Q: ... +class MediaType: + def __init__(self, media_type_raw_line: str) -> None: ... + @property + def is_all_types(self) -> bool: ... + def match(self, other) -> bool: ... + @overload def bytes_to_text(s: bytes, encoding: str) -> str: ... @overload