This commit is contained in:
Maxim Kurnikov
2019-02-05 16:09:42 +03:00
parent be0b2eebb2
commit e4d2b795e3
6 changed files with 38 additions and 23 deletions

View File

@@ -11,7 +11,7 @@ class Model(metaclass=ModelBase):
pass pass
_meta: Any _meta: Any
pk: Any = ... pk: Any = ...
# objects: Manager[Model] objects: Manager[Model]
def __init__(self, *args, **kwargs) -> None: ... def __init__(self, *args, **kwargs) -> None: ...
def delete(self, using: Any = ..., keep_parents: bool = ...) -> Tuple[int, Dict[str, int]]: ... 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: ... def full_clean(self, exclude: Optional[List[str]] = ..., validate_unique: bool = ...) -> None: ...

View File

@@ -13,11 +13,12 @@ from django.urls import ResolverMatch
class BadHeaderError(ValueError): ... class BadHeaderError(ValueError): ...
class HttpResponseBase(BytesIO): class HttpResponseBase:
status_code: int = ... status_code: int = ...
cookies: SimpleCookie = ... cookies: SimpleCookie = ...
reason_phrase: str = ... reason_phrase: str = ...
charset: str = ... charset: str = ...
closed: bool = ...
def __init__( def __init__(
self, self,
content_type: Optional[str] = ..., 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 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 delete_cookie(self, key: str, path: str = "", domain: str = None) -> None: ...
def make_bytes(self, value: object) -> bytes: ... 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): class HttpResponse(HttpResponseBase):
client: Client client: Client
@@ -73,7 +83,6 @@ class HttpResponse(HttpResponseBase):
def content(self) -> bytes: ... def content(self) -> bytes: ...
@content.setter @content.setter
def content(self, value: Any) -> None: ... def content(self, value: Any) -> None: ...
def tell(self) -> int: ...
@property @property
def url(self) -> str: ... def url(self) -> str: ...
def json(self) -> Dict[str, Any]: ... def json(self) -> Dict[str, Any]: ...

View File

@@ -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 django.http.request import HttpRequest
from . import engines as engines
def get_template(template_name: str, using: Optional[str] = ...) -> Any: ... 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 select_template(template_name_list: Union[List[str], str], using: Optional[str] = ...) -> Any: ...
def render_to_string( def render_to_string(
template_name: Union[List[str], str], template_name: Union[List[str], str],
context: Optional[Dict[str, Any]] = ..., context: Optional[Dict[str, Any]] = ...,
request: Optional[WSGIRequest] = ..., request: Optional[HttpRequest] = ...,
using: Optional[str] = ..., using: Optional[str] = ...,
) -> str: ... ) -> str: ...

View File

@@ -9,6 +9,8 @@ from django.http.cookie import SimpleCookie
from django.http.request import HttpRequest from django.http.request import HttpRequest
from django.http.response import HttpResponse, HttpResponseBase from django.http.response import HttpResponse, HttpResponseBase
from django.core.handlers.wsgi import WSGIRequest
CONTENT_TYPE_RE: Pattern CONTENT_TYPE_RE: Pattern
class RedirectCycleError(Exception): class RedirectCycleError(Exception):
@@ -37,13 +39,13 @@ class RequestFactory:
cookies: SimpleCookie = ... cookies: SimpleCookie = ...
errors: BytesIO = ... errors: BytesIO = ...
def __init__(self, *, json_encoder: Any = ..., **defaults: Any) -> None: ... def __init__(self, *, json_encoder: Any = ..., **defaults: Any) -> None: ...
def request(self, **request: Any) -> HttpRequest: ... def request(self, **request: Any) -> WSGIRequest: ...
def get(self, path: str, data: Any = ..., secure: bool = ..., **extra: Any) -> HttpRequest: ... def get(self, path: str, data: Any = ..., secure: bool = ..., **extra: Any) -> WSGIRequest: ...
def post( def post(
self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any
) -> HttpRequest: ... ) -> WSGIRequest: ...
def head(self, path: str, data: Any = ..., secure: bool = ..., **extra: Any) -> HttpRequest: ... def head(self, path: str, data: Any = ..., secure: bool = ..., **extra: Any) -> WSGIRequest: ...
def trace(self, path: str, secure: bool = ..., **extra: Any) -> HttpRequest: ... def trace(self, path: str, secure: bool = ..., **extra: Any) -> WSGIRequest: ...
def options( def options(
self, self,
path: str, path: str,
@@ -51,16 +53,16 @@ class RequestFactory:
content_type: str = ..., content_type: str = ...,
secure: bool = ..., secure: bool = ...,
**extra: Any **extra: Any
) -> HttpRequest: ... ) -> WSGIRequest: ...
def put( def put(
self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any
) -> HttpRequest: ... ) -> WSGIRequest: ...
def patch( def patch(
self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any
) -> HttpRequest: ... ) -> WSGIRequest: ...
def delete( def delete(
self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any self, path: str, data: Any = ..., content_type: str = ..., secure: bool = ..., **extra: Any
) -> HttpRequest: ... ) -> WSGIRequest: ...
def generic( def generic(
self, self,
method: str, method: str,
@@ -69,7 +71,7 @@ class RequestFactory:
content_type: Optional[str] = ..., content_type: Optional[str] = ...,
secure: bool = ..., secure: bool = ...,
**extra: Any **extra: Any
) -> HttpRequest: ... ) -> WSGIRequest: ...
class Client: class Client:
json_encoder: Type[DjangoJSONEncoder] = ... json_encoder: Type[DjangoJSONEncoder] = ...

View File

@@ -27,21 +27,23 @@ class OrderedSet(MutableSet[_K]):
class MultiValueDictKeyError(KeyError): ... class MultiValueDictKeyError(KeyError): ...
class MultiValueDict(MutableMapping[_K, List[_V]]): _Val = Union[_V, List[_V]]
class MultiValueDict(MutableMapping[_K, _V]):
@overload @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 @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 getlist(self, key: _K, default: List[_V] = None) -> List[_V]: ...
def setlist(self, key: _K, list_: List[_V]) -> None: ... def setlist(self, key: _K, list_: List[_V]) -> None: ...
def setlistdefault(self, key: _K, default_list: List[_V] = None) -> List[_V]: ... def setlistdefault(self, key: _K, default_list: List[_V] = None) -> List[_V]: ...
def appendlist(self, key: _K, value: _V) -> None: ... def appendlist(self, key: _K, value: _V) -> None: ...
def lists(self) -> Iterable[Tuple[_K, List[_V]]]: ... 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 # These overrides are needed to convince mypy that this isn't an abstract class
def __delitem__(self, item: _K) -> None: ... def __delitem__(self, item: _K) -> None: ...
def __getitem__(self, item: _K) -> List[_V]: ... def __getitem__(self, item: _K) -> _Val: ... # type: ignore
def __setitem__(self, k: _K, v: List[_V]) -> None: ... def __setitem__(self, k: _K, v: _Val) -> None: ...
def __len__(self) -> int: ... def __len__(self) -> int: ...
def __iter__(self) -> Iterator[_K]: ... def __iter__(self) -> Iterator[_K]: ...

View File

@@ -137,6 +137,9 @@ IGNORED_ERRORS = {
'requests': [ 'requests': [
'Incompatible types in assignment (expression has type "Dict[str, str]", variable has type "QueryDict")' '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': [ 'prefetch_related': [
'Incompatible types in assignment (expression has type "List[Room]", variable has type "QuerySet[Room]")', 'Incompatible types in assignment (expression has type "List[Room]", variable has type "QuerySet[Room]")',
'"None" has no attribute "__iter__"', '"None" has no attribute "__iter__"',