diff --git a/django-stubs/conf/__init__.pyi b/django-stubs/conf/__init__.pyi new file mode 100644 index 0000000..03265d8 --- /dev/null +++ b/django-stubs/conf/__init__.pyi @@ -0,0 +1,4 @@ +from typing import Any + + +settings = ... # type: Any diff --git a/django-stubs/conf/urls/__init__.pyi b/django-stubs/conf/urls/__init__.pyi new file mode 100644 index 0000000..99760f5 --- /dev/null +++ b/django-stubs/conf/urls/__init__.pyi @@ -0,0 +1,23 @@ +# Stubs for django.conf.urls (Python 3.5) + +from typing import Any, Callable, Dict, List, Optional, overload, Tuple, Union + +from django.http.response import HttpResponse +from django.urls import ( + RegexURLPattern, RegexURLResolver +) +from django.urls.resolvers import URLConf + +handler400 = ... # type: str +handler403 = ... # type: str +handler404 = ... # type: str +handler500 = ... # type: str + +def include(arg: Any, namespace: str=None, app_name: str=None) -> Tuple[URLConf, Optional[str], Optional[str]]: ... + +@overload +def url(regex: str, view: Callable[..., HttpResponse], kwargs: Dict[str, Any]=None, name: str=None) -> RegexURLPattern: ... # type: ignore # issue 253 of typing +@overload +def url(regex: str, view: Tuple[URLConf, Optional[str], Optional[str]], kwargs: Dict[str, Any]=None, name: str=None) -> RegexURLResolver: ... +@overload +def url(regex: str, view: List[Union[URLConf, str]], kwargs: Dict[str, Any]=None, name: str=None) -> RegexURLResolver: ... diff --git a/django-stubs/core/__init__.pyi b/django-stubs/core/__init__.pyi new file mode 100644 index 0000000..e69de29 diff --git a/django-stubs/core/files/__init__.pyi b/django-stubs/core/files/__init__.pyi new file mode 100644 index 0000000..58a6fd8 --- /dev/null +++ b/django-stubs/core/files/__init__.pyi @@ -0,0 +1,3 @@ +from django.core.files.base import File + +__all__ = ['File'] diff --git a/django-stubs/core/files/base.pyi b/django-stubs/core/files/base.pyi new file mode 100644 index 0000000..4c05c7e --- /dev/null +++ b/django-stubs/core/files/base.pyi @@ -0,0 +1,28 @@ +# Stubs for django.core.files.base (Python 3.5) + +from typing import Any, Iterable, Iterator, Optional, Sized, Union +from django.core.files.utils import FileProxyMixin + +class File(FileProxyMixin, Sized, Iterable[bytes]): + DEFAULT_CHUNK_SIZE = ... # type: int + file = ... # type: Any + name: Optional[str] = ... # type: ignore + mode = ... # type: str + size = ... # type: int + + def __init__(self, file: Any, name: str=None) -> None: ... + @property + def closed(self) -> bool: ... + def chunks(self, chunk_size: int=None) -> Iterator[bytes]: ... + def multiple_chunks(self, chunk_size: int=None) -> bool: ... + def __enter__(self) -> 'File': ... + def __exit__(self, t: type = None, value: BaseException = None, traceback: Any = None) -> bool: ... + def open(self, mode: str=None) -> None: ... + def close(self) -> None: ... + +class ContentFile(File): + def __init__(self, content: Union[str, bytes], name: Optional[str]=None) -> None: ... + +def endswith_cr(line: Union[str, bytes]) -> bool: ... +def endswith_lf(line: Union[str, bytes]) -> bool: ... +def equals_lf(line: Union[str, bytes]) -> bool: ... diff --git a/django-stubs/core/files/temp.pyi b/django-stubs/core/files/temp.pyi new file mode 100644 index 0000000..9439e13 --- /dev/null +++ b/django-stubs/core/files/temp.pyi @@ -0,0 +1,5 @@ +import tempfile + +NamedTemporaryFile = tempfile.NamedTemporaryFile + +gettempdir = tempfile.gettempdir diff --git a/django-stubs/core/files/uploadedfile.pyi b/django-stubs/core/files/uploadedfile.pyi new file mode 100644 index 0000000..d162c5e --- /dev/null +++ b/django-stubs/core/files/uploadedfile.pyi @@ -0,0 +1,26 @@ +# Stubs for django.core.files.uploadedfile (Python 3.5) + +from typing import Any, Dict, IO, Iterator, Optional, Union +from django.core.files import temp as tempfile +from django.core.files.base import File + +class UploadedFile(File): + content_type = ... # type: Optional[str] + charset = ... # type: Optional[str] + content_type_extra = ... # type: Optional[Dict[str, str]] + def __init__(self, file: IO, name: str=None, content_type: str=None, size: int=None, charset: str=None, content_type_extra: Dict[str, str]=None) -> None: ... + +class TemporaryUploadedFile(UploadedFile): + def __init__(self, name: str, content_type: str, size: int, charset: str, content_type_extra: Dict[str, str]=None) -> None: ... + def temporary_file_path(self) -> str: ... + +class InMemoryUploadedFile(UploadedFile): + field_name = ... # type: Optional[str] + def __init__(self, file: IO, field_name: Optional[str], name: str, content_type: Optional[str], size: int, charset: Optional[str], content_type_extra: Dict[str, str]=None) -> None: ... + def chunks(self, chunk_size: int=None) -> Iterator[bytes]: ... + def multiple_chunks(self, chunk_size: int=None) -> bool: ... + +class SimpleUploadedFile(InMemoryUploadedFile): + def __init__(self, name: str, content: bytes, content_type: str='') -> None: ... + @classmethod + def from_dict(cls: Any, file_dict: Dict[str, Union[str, bytes]]) -> None: ... diff --git a/django-stubs/core/files/uploadhandler.pyi b/django-stubs/core/files/uploadhandler.pyi new file mode 100644 index 0000000..f5c433a --- /dev/null +++ b/django-stubs/core/files/uploadhandler.pyi @@ -0,0 +1,48 @@ +# Stubs for django.core.files.uploadhandler (Python 3.5) + +from typing import Any, Dict, IO, Optional, Tuple +from django.core.files.uploadedfile import UploadedFile, TemporaryUploadedFile +from django.http.request import HttpRequest, QueryDict +from django.utils.datastructures import MultiValueDict + +class UploadFileException(Exception): ... + +class StopUpload(UploadFileException): + connection_reset = ... # type: bool + def __init__(self, connection_reset: bool=False) -> None: ... + +class SkipFile(UploadFileException): ... +class StopFutureHandlers(UploadFileException): ... + +class FileUploadHandler: + chunk_size = ... # type: int + file_name = ... # type: Optional[str] + content_type = ... # type: Optional[str] + content_length = ... # type: Optional[int] + charset = ... # type: Optional[str] + content_type_extra = ... # type: Optional[Dict[str, str]] + request = ... # type: Optional[HttpRequest] + field_name = ... # type: str + def __init__(self, request: HttpRequest=None) -> None: ... + def handle_raw_input(self, input_data: IO[bytes], META: Dict[str, str], content_length: int, boundary: str, encoding: str=None) -> Optional[Tuple[QueryDict, MultiValueDict[str, UploadedFile]]]: ... + def new_file(self, field_name: str, file_name: str, content_type: str, content_length: Optional[int], charset: str=None, content_type_extra: Dict[str, str]=None) -> None: ... + def receive_data_chunk(self, raw_data: bytes, start: int) -> Optional[bytes]: ... + def file_complete(self, file_size: int) -> Optional[UploadedFile]: ... + def upload_complete(self) -> None: ... + +class TemporaryFileUploadHandler(FileUploadHandler): + def __init__(self, request: HttpRequest=None) -> None: ... + file = ... # type: TemporaryUploadedFile + def new_file(self, field_name: str, file_name: str, content_type: str, content_length: Optional[int], charset: str=None, content_type_extra: Dict[str, str]=None) -> None: ... + def receive_data_chunk(self, raw_data: bytes, start: int) -> Optional[bytes]: ... + def file_complete(self, file_size: int) -> Optional[UploadedFile]: ... + +class MemoryFileUploadHandler(FileUploadHandler): + activated = ... # type: bool + file = ... # type: IO[bytes] + def handle_raw_input(self, input_data: IO[bytes], META: Dict[str, str], content_length: int, boundary: str, encoding: str=None) -> Optional[Tuple[QueryDict, MultiValueDict[str, UploadedFile]]]: ... + def new_file(self, field_name: str, file_name: str, content_type: str, content_length: Optional[int], charset: str=None, content_type_extra: Dict[str, str]=None) -> None: ... + def receive_data_chunk(self, raw_data: bytes, start: int) -> Optional[bytes]: ... + def file_complete(self, file_size: int) -> Optional[UploadedFile]: ... + +def load_handler(path: str, *args: Any, **kwargs: Any) -> FileUploadHandler: ... diff --git a/django-stubs/core/files/utils.pyi b/django-stubs/core/files/utils.pyi new file mode 100644 index 0000000..4f3fba1 --- /dev/null +++ b/django-stubs/core/files/utils.pyi @@ -0,0 +1,8 @@ +from typing import BinaryIO, Any, Optional, Tuple, Union + +class FileProxyMixin(BinaryIO): + + newlines = ... # type: Union[str, Tuple[str, ...], None] + softspace = ... # type: bool + + def readinto(self, b: Any) -> Optional[int]: ... diff --git a/django-stubs/http/__init__.pyi b/django-stubs/http/__init__.pyi new file mode 100644 index 0000000..491239b --- /dev/null +++ b/django-stubs/http/__init__.pyi @@ -0,0 +1,21 @@ +from django.http.cookie import SimpleCookie, parse_cookie +from django.http.request import ( + HttpRequest, QueryDict, RawPostDataException, UnreadablePostError, +) +from django.http.response import ( + BadHeaderError, FileResponse, Http404, HttpResponse, + HttpResponseBadRequest, HttpResponseForbidden, HttpResponseGone, + HttpResponseNotAllowed, HttpResponseNotFound, HttpResponseNotModified, + HttpResponsePermanentRedirect, HttpResponseRedirect, + HttpResponseServerError, JsonResponse, StreamingHttpResponse, +) + +__all__ = [ + 'SimpleCookie', 'parse_cookie', 'HttpRequest', 'QueryDict', + 'RawPostDataException', 'UnreadablePostError', + 'HttpResponse', 'StreamingHttpResponse', 'HttpResponseRedirect', + 'HttpResponsePermanentRedirect', 'HttpResponseNotModified', + 'HttpResponseBadRequest', 'HttpResponseForbidden', 'HttpResponseNotFound', + 'HttpResponseNotAllowed', 'HttpResponseGone', 'HttpResponseServerError', + 'Http404', 'BadHeaderError', 'JsonResponse', 'FileResponse', +] diff --git a/django-stubs/http/cookie.pyi b/django-stubs/http/cookie.pyi new file mode 100644 index 0000000..4d6f502 --- /dev/null +++ b/django-stubs/http/cookie.pyi @@ -0,0 +1,8 @@ +# Stubs for django.http.cookie (Python 3.5) + +from typing import Dict +from http.cookies import SimpleCookie, Morsel + +cookie_pickles_properly = ... # type: bool + +def parse_cookie(cookie: str) -> Dict[str, str]: ... diff --git a/django-stubs/http/request.pyi b/django-stubs/http/request.pyi new file mode 100644 index 0000000..ee93906 --- /dev/null +++ b/django-stubs/http/request.pyi @@ -0,0 +1,80 @@ +# Stubs for django.http.request (Python 3.5) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import (Any, BinaryIO, Dict, Iterable, Iterator, List, Optional, overload, Pattern, + Tuple, Union) + +from django.core.files import uploadhandler, uploadedfile +from django.utils.datastructures import MultiValueDict, ImmutableList +from django.urls import ResolverMatch + +RAISE_ERROR = ... # type: object +host_validation_re = ... # type: Pattern + +class UnreadablePostError(IOError): ... +class RawPostDataException(Exception): ... + +UploadHandlerList = Union[List[uploadhandler.FileUploadHandler], + ImmutableList[uploadhandler.FileUploadHandler]] + +class HttpRequest(BinaryIO): + GET = ... # type: QueryDict + POST = ... # type: QueryDict + COOKIES = ... # type: Dict[str, str] + META = ... # type: Dict[str, str] + FILES = ... # type: MultiValueDict[str, uploadedfile.UploadedFile] + path = ... # type: str + path_info = ... # type: str + method = ... # type: Optional[str] + resolver_match = ... # type: ResolverMatch + content_type = ... # type: Optional[str] + content_params = ... # type: Optional[Dict[str, str]] + def __init__(self) -> None: ... + def get_host(self) -> str: ... + def get_port(self) -> str: ... + def get_full_path(self, force_append_slash: bool=False) -> str: ... + def get_signed_cookie(self, key: str, default: str=..., salt: str='', max_age: int=None) -> str: ... + def get_raw_uri(self) -> str: ... + def build_absolute_uri(self, location: str=None) -> str: ... + @property + def scheme(self) -> str: ... + def is_secure(self) -> bool: ... + def is_ajax(self) -> bool: ... + encoding = ... # type: Optional[str] + upload_handlers = ... # type: UploadHandlerList + def parse_file_upload(self, META: Dict[str, str], post_data: BinaryIO) -> Tuple['QueryDict', MultiValueDict[str, uploadedfile.UploadedFile]]: ... + @property + def body(self) -> bytes: ... + def close(self) -> None: ... + def read(self, *args: Any, **kwargs: Any) -> bytes: ... + def readline(self, *args: Any, **kwargs: Any) -> bytes: ... + def xreadlines(self) -> Iterator[bytes]: ... + def __iter__(self) -> Iterator[bytes]: ... + def readlines(self) -> List[bytes]: ... # type: ignore + +class QueryDict(MultiValueDict[str, str]): + encoding = str # type: Any + def __init__(self, query_string: Union[str, bytes, None]=None, mutable: bool=False, encoding: Optional[str]=None) -> None: ... + def __setitem__(self, key: str, value: str) -> None: ... + def __delitem__(self, key: str) -> None: ... + def __copy__(self) -> 'QueryDict': ... + def __deepcopy__(self, memo: Dict[int, object]) -> 'QueryDict': ... + def setlist(self, key: str, list_: List[str]) -> None: ... + def setlistdefault(self, key: str, default_list: List[str]=None) -> List[str]: ... + def appendlist(self, key: str, value: str) -> None: ... + def pop(self, key: str, default: List[str]=None) -> List[str]: ... # type: ignore + def popitem(self) -> Tuple[str, str]: ... + def clear(self) -> None: ... + def setdefault(self, key: str, default: Optional[str]=None) -> str: ... + def copy(self) -> 'QueryDict': ... + def urlencode(self, safe: Optional[str]=None) -> str: ... + +@overload +def bytes_to_text(s: bytes, encoding: str) -> str: ... +@overload +def bytes_to_text(s: str, encoding: str) -> str: ... +@overload +def bytes_to_text(s: None, encoding: str) -> None: ... +def split_domain_port(host: str) -> Tuple[str, str]: ... +def validate_host(host: str, allowed_hosts: Iterable[str]) -> bool: ... diff --git a/django-stubs/http/response.pyi b/django-stubs/http/response.pyi new file mode 100644 index 0000000..93bb132 --- /dev/null +++ b/django-stubs/http/response.pyi @@ -0,0 +1,98 @@ +# Stubs for django.http.response (Python 3.5) + +import datetime +from json import JSONEncoder +from typing import Any, Dict, Iterable, Iterator, List, Optional, overload, Tuple, Type, Union + +from django.http.cookie import SimpleCookie +import six + +class BadHeaderError(ValueError): ... + +class HttpResponseBase(six.Iterator): + status_code = ... # type: int + cookies = ... # type: SimpleCookie + closed = ... # type: bool + reason_phrase = ... # type: str + charset = ... # type: str + def __init__(self, content_type: str=None, status: int=None, reason: str=None, charset: str=None) -> None: ... + def serialize_headers(self) -> bytes: ... + def __bytes__(self) -> bytes: ... + def __setitem__(self, header: str, value: Union[str, bytes]) -> None: ... + def __delitem__(self, header: str) -> None: ... + def __getitem__(self, header: str) -> str: ... + def has_header(self, header: str) -> bool: ... + def __contains__(self, item: object) -> bool: ... + def items(self) -> Iterable[Tuple[str, str]]: ... + @overload + def get(self, header: str, alternate: str) -> str: ... + @overload + def get(self, header: str) -> Optional[str]: ... + def set_cookie(self, key: str, value: str='', max_age: int=None, expires: Union[str, datetime.datetime]=None, path: str='', domain: str=None, secure: bool=False, httponly: bool=False) -> None: ... + def setdefault(self, key: str, value: str) -> None: ... + def set_signed_cookie(self, key: str, value: str, salt: str='', **kwargs: Any) -> None: ... + def delete_cookie(self, key: str, path: str='', domain: str=None) -> None: ... + def make_bytes(self, value: object) -> bytes: ... + def close(self) -> None: ... + def write(self, content: object) -> None: ... + def flush(self) -> None: ... + def tell(self) -> int: ... + def readable(self) -> bool: ... + def seekable(self) -> bool: ... + def writable(self) -> bool: ... + def writelines(self, lines: Iterable[object]) -> None: ... + +class HttpResponse(HttpResponseBase): + streaming = ... # type: bool + def __init__(self, content: object=b'', *args: Any, **kwargs: Any) -> None: ... + def serialize(self) -> bytes: ... + @property + def content(self) -> bytes: ... + @content.setter + def content(self, value: Any) -> None: ... + def __iter__(self) -> Iterator[bytes]: ... + def getvalue(self) -> bytes: ... + +class StreamingHttpResponse(HttpResponseBase): + def __init__(self, streaming_content: Iterable[bytes]=..., *args: Any, **kwargs: Any) -> None: ... + @property + def content(self) -> bytes: ... + @property + def streaming_content(self) -> Iterator[bytes]: ... + @streaming_content.setter + def streaming_content(self, value: Iterable[bytes]) -> None: ... + def __iter__(self) -> Iterator[bytes]: ... + def getvalue(self) -> bytes: ... + +class FileResponse(StreamingHttpResponse): ... + +class HttpResponseRedirectBase(HttpResponse): + allowed_schemes = ... # type: List[str] + def __init__(self, redirect_to: str, *args: Any, **kwargs: Any) -> None: ... + @property + def url(self) -> str: ... + +class HttpResponseRedirect(HttpResponseRedirectBase): ... + +class HttpResponsePermanentRedirect(HttpResponseRedirectBase): ... + +class HttpResponseNotModified(HttpResponse): + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + +class HttpResponseBadRequest(HttpResponse): ... + +class HttpResponseNotFound(HttpResponse): ... + +class HttpResponseForbidden(HttpResponse): ... + +class HttpResponseNotAllowed(HttpResponse): + def __init__(self, permitted_methods: Iterable[str], *args: Any, **kwargs: Any) -> None: ... + +class HttpResponseGone(HttpResponse): ... + +class HttpResponseServerError(HttpResponse): ... + +class Http404(Exception): ... + +class JsonResponse(HttpResponse): + def __init__(self, data: object, encoder: Type[JSONEncoder]=..., safe: bool=True, json_dumps_params: Dict[str, Any]=None, **kwargs: Any) -> None: ... diff --git a/django-stubs/urls/__init__.pyi b/django-stubs/urls/__init__.pyi new file mode 100644 index 0000000..5ee591b --- /dev/null +++ b/django-stubs/urls/__init__.pyi @@ -0,0 +1,20 @@ +from .base import ( # type: ignore # stub not done yet + clear_script_prefix, clear_url_caches, get_script_prefix, get_urlconf, + is_valid_path, resolve, reverse, reverse_lazy, set_script_prefix, + set_urlconf, translate_url, +) +from .exceptions import NoReverseMatch, Resolver404 # type: ignore # stub not done yet +from .resolvers import ( + LocaleRegexProvider, LocaleRegexURLResolver, RegexURLPattern, + RegexURLResolver, ResolverMatch, get_ns_resolver, get_resolver, +) +from .utils import get_callable, get_mod_func + +__all__ = [ + 'LocaleRegexProvider', 'LocaleRegexURLResolver', 'NoReverseMatch', + 'RegexURLPattern', 'RegexURLResolver', 'Resolver404', 'ResolverMatch', + 'clear_script_prefix', 'clear_url_caches', 'get_callable', 'get_mod_func', + 'get_ns_resolver', 'get_resolver', 'get_script_prefix', 'get_urlconf', + 'is_valid_path', 'resolve', 'reverse', 'reverse_lazy', 'set_script_prefix', + 'set_urlconf', 'translate_url', +] diff --git a/django-stubs/urls/resolvers.pyi b/django-stubs/urls/resolvers.pyi new file mode 100644 index 0000000..73cbee5 --- /dev/null +++ b/django-stubs/urls/resolvers.pyi @@ -0,0 +1,75 @@ +# Stubs for django.urls.resolvers (Python 3.5) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Callable, Dict, Iterable, List, Optional, Pattern, Tuple, Union + +from django.http.response import HttpResponse +from django.utils.datastructures import MultiValueDict + +# Auxiliar types +URLPattern = Union['RegexURLResolver', 'RegexURLPattern'] +Params = Dict[str, object] # Arguments for views +# Auxiliar type for allowed resolver configurations +URLConf = Union[str, List[URLPattern]] + +# The result type for regex_helper.normalize() +NormalizedRegexForms = List[Tuple[str, List[str]]] +ReverseLookup = MultiValueDict[str, Tuple[NormalizedRegexForms, str, Params]] +Namespace = Dict[str, Tuple[str, 'RegexURLResolver']] +AppDict = Dict[str, List[str]] + +_View = Callable[..., HttpResponse] + +class ResolverMatch: + func = ... # type: Callable + args = ... # type: Iterable[object] + kwargs = ... # type: Params + url_name = ... # type: Optional[str] + app_names = ... # type: List[str] + app_name = ... # type: str + namespaces = ... # type: List[str] + namespace = ... # type: str + view_name = ... # type: str + def __init__(self, func: Callable, args: Iterable[object], kwargs: Params, url_name: str=None, app_names: Iterable[str]=None, namespaces: Iterable[str]=None) -> None: ... + def __getitem__(self, index: int) -> Any: ... + +def get_resolver(urlconf: Optional[URLConf]=None) -> 'RegexURLResolver': ... +def get_ns_resolver(ns_pattern: str, resolver: 'RegexURLResolver') -> 'RegexURLResolver': ... + +class LocaleRegexProvider: + def __init__(self, regex: Optional[str]) -> None: ... + @property + def regex(self) -> Pattern[str]: ... + +class RegexURLPattern(LocaleRegexProvider): + callback = ... # type: _View + default_args = ... # type: Params + name = ... # type: Optional[str] + def __init__(self, regex: str, callback: _View, default_args: Params=None, name: str=None) -> None: ... + def resolve(self, path: str) -> Optional[ResolverMatch]: ... + def lookup_str(self) -> str: ... + +class RegexURLResolver(LocaleRegexProvider): + urlconf_name = ... # type: URLConf + default_kwargs = ... # type: Params + namespace = ... # type: Optional[str] + app_name = ... # type: Optional[str] + def __init__(self, regex: Optional[str], urlconf_name: URLConf, default_kwargs: Params=None, app_name: str=None, namespace: str=None) -> None: ... + @property + def reverse_dict(self) -> ReverseLookup: ... + @property + def namespace_dict(self) -> Namespace: ... + @property + def app_dict(self) -> AppDict: ... + def resolve(self, path: str) -> ResolverMatch: ... + def urlconf_module(self) -> Union[Iterable[URLPattern], Any]: ... + def url_patterns(self) -> Iterable[URLPattern]: ... + def resolve_error_handler(self, view_type: int) -> Tuple[Callable, Params]: ... + def reverse(self, lookup_view: str, *args: object, **kwargs: object) -> str: ... + +class LocaleRegexURLResolver(RegexURLResolver): + prefix_default_language = ... # type: bool + def __init__(self, urlconf_name: URLConf, default_kwargs: Params=None, app_name: str=None, namespace: str=None, prefix_default_language: bool=True) -> None: ... + @property + def regex(self) -> Pattern[str]: ... diff --git a/django-stubs/urls/utils.pyi b/django-stubs/urls/utils.pyi new file mode 100644 index 0000000..c69dc13 --- /dev/null +++ b/django-stubs/urls/utils.pyi @@ -0,0 +1,6 @@ +# Stubs for django.urls.utils (Python 3.5) + +from typing import Callable, Tuple, Union + +def get_callable(lookup_view: Union[str, Callable]) -> Callable: ... +def get_mod_func(callback: str) -> Tuple[str, str]: ... diff --git a/django-stubs/utils/__init__.pyi b/django-stubs/utils/__init__.pyi new file mode 100644 index 0000000..e69de29 diff --git a/django-stubs/utils/datastructures.pyi b/django-stubs/utils/datastructures.pyi new file mode 100644 index 0000000..aa3a6dd --- /dev/null +++ b/django-stubs/utils/datastructures.pyi @@ -0,0 +1,57 @@ +# Stubs for django.utils.datastructures (Python 3.5) + +from collections import OrderedDict + +from typing import (Any, Callable, Dict, Generic, Hashable, Iterable, Iterator, List, Mapping, + MutableMapping, MutableSet, Optional, overload, Tuple, TypeVar, Union) + +KT = TypeVar('KT') +VT = TypeVar('VT') + +class OrderedSet(MutableSet[KT], Generic[KT]): + dict = ... # type: OrderedDict[KT, None] + def __init__(self, iterable: Iterable[KT]=None) -> None: ... + def add(self, item: KT) -> None: ... + def remove(self, item: KT) -> None: ... + def discard(self, item: KT) -> None: ... + +class MultiValueDictKeyError(KeyError): ... + +class MultiValueDict(MutableMapping[KT, VT], Generic[KT, VT]): + def __init__(self, key_to_list_mapping: Iterable[Tuple[KT, List[VT]]]=...) -> None: ... + def __copy__(self) -> 'MultiValueDict[KT, VT]': ... + def __deepcopy__(self, memo: Dict[int, object]) -> 'MultiValueDict[KT, VT]': ... + def __getitem__(self, key: KT) -> Union[VT, List[VT]]: ... # type: ignore + def pop(self, key: KT, default: List[VT]=None) -> List[VT]: ... # type: ignore + def __getstate__(self) -> Dict[str, Any]: ... + def __setstate__(self, obj_dict: Dict[str, Any]) -> None: ... + def get(self, key: KT, default: VT=None) -> Union[Optional[VT], List[VT]]: ... # type: ignore + def getlist(self, key: KT, default: List[VT]=None) -> List[VT]: ... + def setlist(self, key: KT, list_: List[VT]) -> None: ... + def setlistdefault(self, key: KT, default_list: List[VT]=None) -> List[VT]: ... + def appendlist(self, key: KT, value: VT) -> None: ... + def lists(self) -> Iterable[Tuple[KT, List[VT]]]: ... + def copy(self) -> 'MultiValueDict[KT, VT]': ... + @overload # type: ignore + def update(self, args: Mapping[KT, VT]) -> None: ... + @overload + def update(self, *args: Mapping[KT, VT], **kwargs: Iterable[Tuple[KT, VT]]) -> None: ... # type: ignore + def dict(self) -> Dict[KT, Union[VT, List[VT]]]: ... + + # These overrides are needed to convince mypy that this isn't an abstract class + def __delitem__(self, k: KT) -> None: ... + def __setitem__(self, k: KT, v: VT) -> None: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[KT]: ... + +class ImmutableList(Tuple[VT, ...], Generic[VT]): + warning = ... # type: str + def complain(self, *wargs: Any, **kwargs: Any) -> None: ... + +class DictWrapper(Dict[str, VT], Generic[VT]): + func = ... # type: Callable[[VT], VT] + prefix = ... # type: str + @overload + def __init__(self, data: Mapping[str, VT], func: Callable[[VT], VT], prefix: str) -> None: ... + @overload + def __init__(self, data: Iterable[Tuple[str, VT]], func: Callable[[VT], VT], prefix: str) -> None: ... diff --git a/django-stubs/utils/timezone.pyi b/django-stubs/utils/timezone.pyi new file mode 100644 index 0000000..cd86e85 --- /dev/null +++ b/django-stubs/utils/timezone.pyi @@ -0,0 +1,52 @@ +# Stubs for django.utils.timezone (Python 3.5) + +from typing import Any, Optional, Union +from datetime import tzinfo, datetime, timedelta +from contextlib import ContextDecorator + +class UTC(tzinfo): + def utcoffset(self, dt: Optional[datetime]) -> Optional[timedelta]: ... + def tzname(self, dt: Optional[datetime]) -> str: ... + def dst(self, dt: Optional[datetime]) -> Optional[timedelta]: ... + +class FixedOffset(tzinfo): + def __init__(self, offset: int=None, name: str=None) -> None: ... + def utcoffset(self, dt: Optional[datetime]) -> Optional[timedelta]: ... + def tzname(self, dt: Optional[datetime]) -> str: ... + def dst(self, dt: Optional[datetime]) -> Optional[timedelta]: ... + +class ReferenceLocalTimezone(tzinfo): + STDOFFSET = ... # type: timedelta + DSTOFFSET = ... # type: timedelta + DSTDIFF = ... # type: timedelta + def __init__(self) -> None: ... + def utcoffset(self, dt: Optional[datetime]) -> Optional[timedelta]: ... + def dst(self, dt: Optional[datetime]) -> Optional[timedelta]: ... + def tzname(self, dt: Optional[datetime]) -> str: ... + +class LocalTimezone(ReferenceLocalTimezone): + def tzname(self, dt: Optional[datetime]) -> str: ... + +utc = ... # type: UTC + +def get_fixed_timezone(offset: Union[timedelta, int]) -> tzinfo: ... +def get_default_timezone() -> tzinfo: ... +def get_default_timezone_name() -> str: ... +def get_current_timezone() -> tzinfo: ... +def get_current_timezone_name() -> str: ... +def activate(timezone: tzinfo) -> None: ... +def deactivate() -> None: ... + +class override(ContextDecorator): + timezone = ... # type: tzinfo + old_timezone = ... # type: tzinfo + def __init__(self, timezone: tzinfo) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, exc_type: object, exc_value: object, traceback: object) -> None: ... + +def localtime(value: datetime, timezone: tzinfo=None) -> datetime: ... +def now() -> datetime: ... +def is_aware(value: datetime) -> bool: ... +def is_naive(value: datetime) -> bool: ... +def make_aware(value: datetime, timezone: tzinfo=None, is_dst: bool=None) -> datetime: ... +def make_naive(value: datetime, timezone: tzinfo=None) -> datetime: ... diff --git a/django-stubs/views/__init__.py b/django-stubs/views/__init__.py new file mode 100644 index 0000000..95b0c6b --- /dev/null +++ b/django-stubs/views/__init__.py @@ -0,0 +1,3 @@ +from django.views.generic.base import View + +__all__ = ['View'] diff --git a/django-stubs/views/generic/__init__.pyi b/django-stubs/views/generic/__init__.pyi new file mode 100644 index 0000000..66f305c --- /dev/null +++ b/django-stubs/views/generic/__init__.pyi @@ -0,0 +1,7 @@ +from django.views.generic.base import RedirectView as RedirectView, TemplateView as TemplateView, View as View +from django.views.generic.dates import ArchiveIndexView as ArchiveIndexView, DateDetailView as DateDetailView, DayArchiveView as DayArchiveView, MonthArchiveView as MonthArchiveView, TodayArchiveView as TodayArchiveView, WeekArchiveView as WeekArchiveView, YearArchiveView as YearArchiveView +from django.views.generic.detail import DetailView as DetailView +from django.views.generic.edit import CreateView as CreateView, DeleteView as DeleteView, FormView as FormView, UpdateView as UpdateView +from django.views.generic.list import ListView as ListView + +class GenericViewError(Exception): ... diff --git a/django-stubs/views/generic/base.pyi b/django-stubs/views/generic/base.pyi new file mode 100644 index 0000000..83a6e7c --- /dev/null +++ b/django-stubs/views/generic/base.pyi @@ -0,0 +1,46 @@ +from typing import Any, Callable, Dict, List, Optional, Tuple, Type + +from django import http + +logger = ... # type: Any + +class ContextMixin: + def get_context_data(self, **kwargs: object) -> Dict[str, object]: ... + +class View: + http_method_names = ... # type: List[str] + request = ... # type: http.HttpRequest + args = ... # type: Tuple[object, ...] + kwargs = ... # type: Dict[str, object] + def __init__(self, **kwargs: object) -> None: ... + @classmethod + def as_view(cls: Any, **initkwargs: object) -> Callable[..., http.HttpResponse]: ... + def dispatch(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... + def http_method_not_allowed(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... + def options(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... + +class TemplateResponseMixin: + template_name = ... # type: str + template_engine = ... # type: Optional[str] + response_class = ... # type: Type[http.HttpResponse] + content_type = ... # type: Optional[str] + request = ... # type: http.HttpRequest + def render_to_response(self, context: Dict[str, object], **response_kwargs: object) -> http.HttpResponse: ... + def get_template_names(self) -> List[str]: ... + +class TemplateView(TemplateResponseMixin, ContextMixin, View): + def get(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... + +class RedirectView(View): + permanent = ... # type: bool + url = ... # type: Optional[str] + pattern_name = ... # type: Optional[str] + query_string = ... # type: bool + def get_redirect_url(self, *args: object, **kwargs: object) -> Optional[str]: ... + def get(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... + def head(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... + def post(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... + def options(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... + def delete(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... + def put(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... + def patch(self, request: http.HttpRequest, *args: object, **kwargs: object) -> http.HttpResponse: ... diff --git a/django-stubs/views/generic/dates.pyi b/django-stubs/views/generic/dates.pyi new file mode 100644 index 0000000..5d0f4b8 --- /dev/null +++ b/django-stubs/views/generic/dates.pyi @@ -0,0 +1,118 @@ +import datetime +from typing import Any, Dict, Optional, Sequence, Tuple, Type + +from django.db import models +from django.http import HttpRequest, HttpResponse +from django.views.generic.base import View +from django.views.generic.detail import BaseDetailView, SingleObjectTemplateResponseMixin +from django.views.generic.list import MultipleObjectMixin, MultipleObjectTemplateResponseMixin + +class YearMixin: + year_format = ... # type: str + year = ... # type: Optional[str] + kwargs = ... # type: Dict[str, object] + request = ... # type: HttpRequest + def get_year_format(self) -> str: ... + def get_year(self) -> str: ... + def get_next_year(self, date: datetime.date) -> Optional[datetime.date]: ... + def get_previous_year(self, date: datetime.date) -> Optional[datetime.date]: ... + +class MonthMixin: + month_format = ... # type: str + month = ... # type: Optional[str] + request = ... # type: HttpRequest + kwargs = ... # type: Dict[str, object] + def get_month_format(self) -> str: ... + def get_month(self) -> str: ... + def get_next_month(self, date: datetime.date) -> Optional[datetime.date]: ... + def get_previous_month(self, date: datetime.date) -> Optional[datetime.date]: ... + +class DayMixin: + day_format = ... # type: str + day = ... # type: Optional[str] + request = ... # type: HttpRequest + kwargs = ... # type: Dict[str, object] + def get_day_format(self) -> str: ... + def get_day(self) -> str: ... + def get_next_day(self, date: datetime.date) -> Optional[datetime.date]: ... + def get_previous_day(self, date: datetime.date) -> Optional[datetime.date]: ... + +class WeekMixin: + week_format = ... # type: str + week = ... # type: Optional[str] + request = ... # type: HttpRequest + kwargs = ... # type: Dict[str, object] + def get_week_format(self) -> str: ... + def get_week(self) -> str: ... + def get_next_week(self, date: datetime.date) -> Optional[datetime.date]: ... + def get_previous_week(self, date: datetime.date) -> Optional[datetime.date]: ... + +class DateMixin: + date_field = ... # type: Optional[str] + allow_future = ... # type: bool + model = ... # type: Optional[Type[models.Model]] + def get_date_field(self) -> str: ... + def get_allow_future(self) -> bool: ... + def uses_datetime_field(self) -> bool: ... + +DatedItems = Tuple[Optional[Sequence[datetime.date]], Sequence[object], Dict[str, Any]] + +class BaseDateListView(MultipleObjectMixin, DateMixin, View): + allow_empty = ... # type: bool + date_list_period = ... # type: str + def render_to_response(self, context: Dict[str, object], **response_kwargs: object) -> HttpResponse: ... + def get(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ... + def get_dated_items(self) -> DatedItems: ... + def get_ordering(self) -> Sequence[str]: ... + def get_dated_queryset(self, **lookup: object) -> models.query.QuerySet: ... + def get_date_list_period(self) -> str: ... + def get_date_list(self, queryset: models.query.QuerySet, date_type: str = None, ordering: str = ...) -> models.query.QuerySet: ... + +class BaseArchiveIndexView(BaseDateListView): + context_object_name = ... # type: str + def get_dated_items(self) -> DatedItems: ... + +class ArchiveIndexView(MultipleObjectTemplateResponseMixin, BaseArchiveIndexView): + template_name_suffix = ... # type: str + +class BaseYearArchiveView(YearMixin, BaseDateListView): + date_list_period = ... # type: str + make_object_list = ... # type: bool + def get_dated_items(self) -> DatedItems: ... + def get_make_object_list(self) -> bool: ... + +class YearArchiveView(MultipleObjectTemplateResponseMixin, BaseYearArchiveView): + template_name_suffix = ... # type: str + +class BaseMonthArchiveView(YearMixin, MonthMixin, BaseDateListView): + date_list_period = ... # type: str + def get_dated_items(self) -> DatedItems: ... + +class MonthArchiveView(MultipleObjectTemplateResponseMixin, BaseMonthArchiveView): + template_name_suffix = ... # type: str + +class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView): + def get_dated_items(self) -> DatedItems: ... + +class WeekArchiveView(MultipleObjectTemplateResponseMixin, BaseWeekArchiveView): + template_name_suffix = ... # type: str + +class BaseDayArchiveView(YearMixin, MonthMixin, DayMixin, BaseDateListView): + def get_dated_items(self) -> DatedItems: ... + +class DayArchiveView(MultipleObjectTemplateResponseMixin, BaseDayArchiveView): + template_name_suffix = ... # type: str + +class BaseTodayArchiveView(BaseDayArchiveView): + def get_dated_items(self) -> DatedItems: ... + +class TodayArchiveView(MultipleObjectTemplateResponseMixin, BaseTodayArchiveView): + template_name_suffix = ... # type: str + +class BaseDateDetailView(YearMixin, MonthMixin, DayMixin, DateMixin, BaseDetailView): + def get_object(self, queryset: models.query.QuerySet=None) -> models.Model: ... + +class DateDetailView(SingleObjectTemplateResponseMixin, BaseDateDetailView): + template_name_suffix = ... # type: str + +def timezone_today() -> datetime.date: ... diff --git a/django-stubs/views/generic/detail.pyi b/django-stubs/views/generic/detail.pyi new file mode 100644 index 0000000..c03a3be --- /dev/null +++ b/django-stubs/views/generic/detail.pyi @@ -0,0 +1,35 @@ +from typing import Any, Dict, List, Optional, Type + +from django.db import models +from django.http import HttpResponse, HttpRequest +from django.views.generic.base import ContextMixin, TemplateResponseMixin, View + +class SingleObjectMixin(ContextMixin): + model = ... # type: Optional[Type[models.Model]] + queryset = ... # type: Optional[models.query.QuerySet] + slug_field = ... # type: str + context_object_name = ... # type: Optional[str] + slug_url_kwarg = ... # type: str + pk_url_kwarg = ... # type: str + query_pk_and_slug = ... # type: bool + object = ... # type: models.Model + kwargs = ... # type: Dict[str, object] + def get_object(self, queryset: models.query.QuerySet = None) -> models.Model: ... + def get_queryset(self) -> models.query.QuerySet: ... + def get_slug_field(self) -> str: ... + def get_context_object_name(self, obj: Any) -> Optional[str]: ... + def get_context_data(self, **kwargs: object) -> Dict[str, object]: ... + +class BaseDetailView(SingleObjectMixin, View): + def render_to_response(self, context: Dict[str, object], **response_kwargs: object) -> HttpResponse: ... + object = ... # type: models.Model + def get(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ... + +class SingleObjectTemplateResponseMixin(TemplateResponseMixin): + template_name_field = ... # type: Optional[str] + template_name_suffix = ... # type: str + model = ... # type: Optional[Type[models.Model]] + object = ... # type: models.Model + def get_template_names(self) -> List[str]: ... + +class DetailView(SingleObjectTemplateResponseMixin, BaseDetailView): ... diff --git a/django-stubs/views/generic/edit.pyi b/django-stubs/views/generic/edit.pyi new file mode 100644 index 0000000..cb4aa8b --- /dev/null +++ b/django-stubs/views/generic/edit.pyi @@ -0,0 +1,75 @@ +from typing import Any, Dict, List, Optional, Type + +from django.db import models +from django.forms import models as model_forms, Form # type: ignore # This will be solved when adding forms module +from django.http import HttpResponse, HttpRequest +from django.views.generic.base import ContextMixin, TemplateResponseMixin, View +from django.views.generic.detail import BaseDetailView, SingleObjectMixin, SingleObjectTemplateResponseMixin + +class FormMixin(ContextMixin): + initial = ... # type: Dict[str, object] + form_class = ... # type: Optional[Type[Form]] + success_url = ... # type: Optional[str] + prefix = ... # type: Optional[str] + request = ... # type: HttpRequest + def render_to_response(self, context: Dict[str, object], **response_kwargs: object) -> HttpResponse: ... + def get_initial(self) -> Dict[str, object]: ... + def get_prefix(self) -> Optional[str]: ... + def get_form_class(self) -> Type[Form]: ... + def get_form(self, form_class: Type[Form] = None) -> Form: ... + def get_form_kwargs(self) -> Dict[str, Any]: ... + def get_success_url(self) -> str: ... + def form_valid(self, form: Form) -> HttpResponse: ... + def form_invalid(self, form: Form) -> HttpResponse: ... + def get_context_data(self, **kwargs: object) -> Dict[str, object]: ... + +class ModelFormMixin(FormMixin, SingleObjectMixin): + fields = ... # type: Optional[List[str]] + object = ... # type: models.Model + def get_form_class(self) -> Type[Form]: ... + def get_form_kwargs(self) -> Dict[str, object]: ... + def get_success_url(self) -> str: ... + def form_valid(self, form: Form) -> HttpResponse: ... + +class ProcessFormView(View): + def render_to_response(self, context: Dict[str, object], **response_kwargs: object) -> HttpResponse: ... + def get_context_data(self, **kwargs: object) -> Dict[str, object]: ... + def get_form(self, form_class: Type[Form] = None) -> Form: ... + def form_valid(self, form: Form) -> HttpResponse: ... + def form_invalid(self, form: Form) -> HttpResponse: ... + def get(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ... + def post(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ... + def put(self, *args: Any, **kwargs: Any) -> HttpResponse: ... + +class BaseFormView(FormMixin, ProcessFormView): ... +class FormView(TemplateResponseMixin, BaseFormView): ... + +class BaseCreateView(ModelFormMixin, ProcessFormView): + object = ... # type: models.Model + def get(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ... + def post(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ... + +class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView): + template_name_suffix = ... # type: str + +class BaseUpdateView(ModelFormMixin, ProcessFormView): + object = ... # type: models.Model + def get(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ... + def post(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ... + +class UpdateView(SingleObjectTemplateResponseMixin, BaseUpdateView): + template_name_suffix = ... # type: str + +_object = object + +class DeletionMixin: + success_url = ... # type: Optional[str] + object = ... # type: models.Model + def delete(self, request: HttpRequest, *args: _object, **kwargs: _object) -> HttpResponse: ... + def post(self, request: HttpRequest, *args: _object, **kwargs: _object) -> HttpResponse: ... + def get_success_url(self) -> str: ... + +class BaseDeleteView(DeletionMixin, BaseDetailView): ... + +class DeleteView(SingleObjectTemplateResponseMixin, BaseDeleteView): + template_name_suffix = ... # type: str diff --git a/django-stubs/views/generic/list.pyi b/django-stubs/views/generic/list.pyi new file mode 100644 index 0000000..51ca8e6 --- /dev/null +++ b/django-stubs/views/generic/list.pyi @@ -0,0 +1,43 @@ +from typing import Any, Dict, List, Optional, Sequence, Tuple, Type + +from django.db.models import Model +from django.db.models.query import QuerySet +from django.core.paginator import Paginator # type: ignore # This will be fixed when adding the paginator module +from django.http import HttpRequest, HttpResponse +from django.views.generic.base import ContextMixin, TemplateResponseMixin, View + +class MultipleObjectMixin(ContextMixin): + allow_empty = ... # type: bool + queryset = ... # type: Optional[QuerySet] + model = ... # type: Optional[Type[Model]] + paginate_by = ... # type: Optional[int] + paginate_orphans = ... # type: int + context_object_name = ... # type: Optional[str] + paginator_class = ... # type: Type[Paginator] + page_kwarg = ... # type: str + ordering = ... # type: Sequence[str] + request = ... # type: HttpRequest + kwargs = ... # type: Dict[str, object] + object_list = ... # type: QuerySet + + def get_queryset(self) -> QuerySet: ... + def get_ordering(self) -> Sequence[str]: ... + def paginate_queryset(self, queryset: QuerySet, page_size: int) -> Tuple[Paginator, int, QuerySet, bool]: ... + def get_paginate_by(self, queryset: QuerySet) -> Optional[int]: ... + def get_paginator(self, queryset: QuerySet, per_page: int, orphans: int = ..., allow_empty_first_page: bool = ..., **kwargs: Any) -> Paginator: ... + def get_paginate_orphans(self) -> int: ... + def get_allow_empty(self) -> bool: ... + def get_context_object_name(self, object_list: QuerySet) -> Optional[str]: ... + def get_context_data(self, **kwargs: object) -> Dict[str, object]: ... + +class BaseListView(MultipleObjectMixin, View): + object_list = ... # type: QuerySet + def render_to_response(self, context: Dict[str, object], **response_kwargs: object) -> HttpResponse: ... + def get(self, request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse: ... + +class MultipleObjectTemplateResponseMixin(TemplateResponseMixin): + template_name_suffix = ... # type: str + object_list = ... # type: QuerySet + def get_template_names(self) -> List[str]: ... + +class ListView(MultipleObjectTemplateResponseMixin, BaseListView): ...