From e4d2b795e36c32c4ea8822ba19fcec160b61e488 Mon Sep 17 00:00:00 2001 From: Maxim Kurnikov Date: Tue, 5 Feb 2019 16:09:42 +0300 Subject: [PATCH] fix ci --- django-stubs/db/models/base.pyi | 2 +- django-stubs/http/response.pyi | 13 +++++++++++-- django-stubs/template/loader.pyi | 7 +++---- django-stubs/test/client.pyi | 22 ++++++++++++---------- django-stubs/utils/datastructures.pyi | 14 ++++++++------ scripts/typecheck_tests.py | 3 +++ 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index 2cf36ab..98b17d1 100644 --- a/django-stubs/db/models/base.pyi +++ b/django-stubs/db/models/base.pyi @@ -11,7 +11,7 @@ class Model(metaclass=ModelBase): pass _meta: Any pk: Any = ... - # objects: Manager[Model] + objects: Manager[Model] def __init__(self, *args, **kwargs) -> None: ... def delete(self, using: Any = ..., keep_parents: bool = ...) -> Tuple[int, Dict[str, int]]: ... def full_clean(self, exclude: Optional[List[str]] = ..., validate_unique: bool = ...) -> None: ... diff --git a/django-stubs/http/response.pyi b/django-stubs/http/response.pyi index 85afa0b..77f306c 100644 --- a/django-stubs/http/response.pyi +++ b/django-stubs/http/response.pyi @@ -13,11 +13,12 @@ from django.urls import ResolverMatch class BadHeaderError(ValueError): ... -class HttpResponseBase(BytesIO): +class HttpResponseBase: status_code: int = ... cookies: SimpleCookie = ... reason_phrase: str = ... charset: str = ... + closed: bool = ... def __init__( self, content_type: Optional[str] = ..., @@ -51,6 +52,15 @@ class HttpResponseBase(BytesIO): 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: Union[str, bytes]) -> 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]): ... + def __iter__(self) -> Iterator[bytes]: ... class HttpResponse(HttpResponseBase): client: Client @@ -73,7 +83,6 @@ class HttpResponse(HttpResponseBase): def content(self) -> bytes: ... @content.setter def content(self, value: Any) -> None: ... - def tell(self) -> int: ... @property def url(self) -> str: ... def json(self) -> Dict[str, Any]: ... diff --git a/django-stubs/template/loader.pyi b/django-stubs/template/loader.pyi index 4d83c33..527a596 100644 --- a/django-stubs/template/loader.pyi +++ b/django-stubs/template/loader.pyi @@ -1,13 +1,12 @@ -from typing import Dict, List, Optional, Union, Any +from typing import Any, Dict, List, Optional, Union -from django.core.handlers.wsgi import WSGIRequest -from . import engines as engines +from django.http.request import HttpRequest def get_template(template_name: str, using: Optional[str] = ...) -> Any: ... def select_template(template_name_list: Union[List[str], str], using: Optional[str] = ...) -> Any: ... def render_to_string( template_name: Union[List[str], str], context: Optional[Dict[str, Any]] = ..., - request: Optional[WSGIRequest] = ..., + request: Optional[HttpRequest] = ..., using: Optional[str] = ..., ) -> str: ... diff --git a/django-stubs/test/client.pyi b/django-stubs/test/client.pyi index c06bfbe..2a04e78 100644 --- a/django-stubs/test/client.pyi +++ b/django-stubs/test/client.pyi @@ -9,6 +9,8 @@ from django.http.cookie import SimpleCookie from django.http.request import HttpRequest from django.http.response import HttpResponse, HttpResponseBase +from django.core.handlers.wsgi import WSGIRequest + CONTENT_TYPE_RE: Pattern class RedirectCycleError(Exception): @@ -37,13 +39,13 @@ class RequestFactory: cookies: SimpleCookie = ... errors: BytesIO = ... def __init__(self, *, json_encoder: Any = ..., **defaults: Any) -> None: ... - def request(self, **request: Any) -> HttpRequest: ... - def get(self, path: str, data: Any = ..., secure: bool = ..., **extra: Any) -> HttpRequest: ... + def request(self, **request: Any) -> WSGIRequest: ... + def get(self, path: str, data: Any = ..., secure: bool = ..., **extra: Any) -> WSGIRequest: ... def post( self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any - ) -> HttpRequest: ... - def head(self, path: str, data: Any = ..., secure: bool = ..., **extra: Any) -> HttpRequest: ... - def trace(self, path: str, secure: bool = ..., **extra: Any) -> HttpRequest: ... + ) -> WSGIRequest: ... + def head(self, path: str, data: Any = ..., secure: bool = ..., **extra: Any) -> WSGIRequest: ... + def trace(self, path: str, secure: bool = ..., **extra: Any) -> WSGIRequest: ... def options( self, path: str, @@ -51,16 +53,16 @@ class RequestFactory: content_type: str = ..., secure: bool = ..., **extra: Any - ) -> HttpRequest: ... + ) -> WSGIRequest: ... def put( self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any - ) -> HttpRequest: ... + ) -> WSGIRequest: ... def patch( self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any - ) -> HttpRequest: ... + ) -> WSGIRequest: ... def delete( self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any - ) -> HttpRequest: ... + ) -> WSGIRequest: ... def generic( self, method: str, @@ -69,7 +71,7 @@ class RequestFactory: content_type: Optional[str] = ..., secure: bool = ..., **extra: Any - ) -> HttpRequest: ... + ) -> WSGIRequest: ... class Client: json_encoder: Type[DjangoJSONEncoder] = ... diff --git a/django-stubs/utils/datastructures.pyi b/django-stubs/utils/datastructures.pyi index b99239b..3f4ef50 100644 --- a/django-stubs/utils/datastructures.pyi +++ b/django-stubs/utils/datastructures.pyi @@ -27,21 +27,23 @@ class OrderedSet(MutableSet[_K]): class MultiValueDictKeyError(KeyError): ... -class MultiValueDict(MutableMapping[_K, List[_V]]): +_Val = Union[_V, List[_V]] + +class MultiValueDict(MutableMapping[_K, _V]): @overload - def __init__(self, key_to_list_mapping: Iterable[Tuple[_K, List[_V]]] = ...) -> None: ... + def __init__(self, key_to_list_mapping: Iterable[Tuple[_K, _Val]] = ...) -> None: ... @overload - def __init__(self, key_to_list_mapping: Mapping[_K, List[_V]] = ...) -> None: ... + def __init__(self, key_to_list_mapping: Mapping[_K, _Val] = ...) -> None: ... def getlist(self, key: _K, default: List[_V] = None) -> List[_V]: ... def setlist(self, key: _K, list_: List[_V]) -> None: ... def setlistdefault(self, key: _K, default_list: List[_V] = None) -> List[_V]: ... def appendlist(self, key: _K, value: _V) -> None: ... def lists(self) -> Iterable[Tuple[_K, List[_V]]]: ... - def dict(self) -> Dict[_K, List[_V]]: ... + def dict(self) -> Dict[_K, _Val]: ... # These overrides are needed to convince mypy that this isn't an abstract class def __delitem__(self, item: _K) -> None: ... - def __getitem__(self, item: _K) -> List[_V]: ... - def __setitem__(self, k: _K, v: List[_V]) -> None: ... + def __getitem__(self, item: _K) -> _Val: ... # type: ignore + def __setitem__(self, k: _K, v: _Val) -> None: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_K]: ... diff --git a/scripts/typecheck_tests.py b/scripts/typecheck_tests.py index 6947dfe..7418991 100644 --- a/scripts/typecheck_tests.py +++ b/scripts/typecheck_tests.py @@ -137,6 +137,9 @@ IGNORED_ERRORS = { 'requests': [ 'Incompatible types in assignment (expression has type "Dict[str, str]", variable has type "QueryDict")' ], + 'responses': [ + 'Argument 1 to "TextIOWrapper" has incompatible type "HttpResponse"; expected "IO[bytes]"' + ], 'prefetch_related': [ 'Incompatible types in assignment (expression has type "List[Room]", variable has type "QuerySet[Room]")', '"None" has no attribute "__iter__"',