mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-11 14:31:56 +08:00
Minor fixes to improve django-stubs (#695)
* Use `Sequence` instead of `Iterable` for `send_messages`.
According to the documentation
(https://docs.djangoproject.com/en/3.2/topics/email/#email-backends),
`email_messages` is a list. Using `Iterable` will make it hard for
subclasses to implement this method utilizing functions like `__len__`.
While this still allows subclasses to accept `Iterable`.
* Fix function signature of `authenticate` of `BaseBackend`.
1. BaseBackend no longer requires the username and password argument.
They were removed 3 years ago in the commit below when `BaseBackend` is added:
75337a6050
2. `request` is optional for `authenticate` method.
According to django documentation, the authenticate method does not
necessarily require the request object.
https://docs.djangoproject.com/en/3.2/topics/auth/default/#authenticating-users
* Tighten the type of `streaming_content` to `Iterator[bytes]`.
It is an iterator of a bytestring according to the documentation:
https://docs.djangoproject.com/en/3.2/ref/request-response/#django.http.StreamingHttpResponse.streaming_content
* Fix function signature of `django.contrib.staticfiles.serve`.
Since this `serve` function uses `django.views.static.serve` that
accepts `HttpRequest` as its first argument, it is more reasonable
to type it with `HttpRequest` instead of `WSGIRequest`.
Related:
https://github.com/django/django/blob/main/django/contrib/staticfiles/views.py#L39
This commit is contained in:
@@ -10,9 +10,7 @@ _AnyUser = Union[Model, AnonymousUser]
|
|||||||
UserModel: Any
|
UserModel: Any
|
||||||
|
|
||||||
class BaseBackend:
|
class BaseBackend:
|
||||||
def authenticate(
|
def authenticate(self, request: Optional[HttpRequest], **kwargs: Any) -> Optional[AbstractBaseUser]: ...
|
||||||
self, request: HttpRequest, username: Optional[str] = ..., password: Optional[str] = ..., **kwargs: Any
|
|
||||||
) -> Optional[AbstractBaseUser]: ...
|
|
||||||
def get_user(self, user_id: int) -> Optional[AbstractBaseUser]: ...
|
def get_user(self, user_id: int) -> Optional[AbstractBaseUser]: ...
|
||||||
def get_user_permissions(self, user_obj: _AnyUser, obj: Optional[Model] = ...) -> Set[str]: ...
|
def get_user_permissions(self, user_obj: _AnyUser, obj: Optional[Model] = ...) -> Set[str]: ...
|
||||||
def get_group_permissions(self, user_obj: _AnyUser, obj: Optional[Model] = ...) -> Set[str]: ...
|
def get_group_permissions(self, user_obj: _AnyUser, obj: Optional[Model] = ...) -> Set[str]: ...
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from django.core.handlers.wsgi import WSGIRequest
|
from django.http.request import HttpRequest
|
||||||
from django.http.response import FileResponse
|
from django.http.response import FileResponse
|
||||||
|
|
||||||
def serve(request: WSGIRequest, path: str, insecure: bool = ..., **kwargs: Any) -> FileResponse: ...
|
def serve(request: HttpRequest, path: str, insecure: bool = ..., **kwargs: Any) -> FileResponse: ...
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import types
|
import types
|
||||||
from typing import Any, Iterable, Optional, Type, TypeVar
|
from typing import Any, Optional, Sequence, Type, TypeVar
|
||||||
|
|
||||||
from django.core.mail.message import EmailMessage
|
from django.core.mail.message import EmailMessage
|
||||||
|
|
||||||
@@ -13,4 +13,4 @@ class BaseEmailBackend:
|
|||||||
def __exit__(
|
def __exit__(
|
||||||
self, exc_type: Type[BaseException], exc_value: BaseException, traceback: types.TracebackType
|
self, exc_type: Type[BaseException], exc_value: BaseException, traceback: types.TracebackType
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
def send_messages(self, email_messages: Iterable[EmailMessage]) -> int: ...
|
def send_messages(self, email_messages: Sequence[EmailMessage]) -> int: ...
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ class HttpResponse(HttpResponseBase):
|
|||||||
|
|
||||||
class StreamingHttpResponse(HttpResponseBase):
|
class StreamingHttpResponse(HttpResponseBase):
|
||||||
content: Any
|
content: Any
|
||||||
streaming_content: Iterator[Any]
|
streaming_content: Iterator[bytes]
|
||||||
def __init__(self, streaming_content: Iterable[Any] = ..., *args: Any, **kwargs: Any) -> None: ...
|
def __init__(self, streaming_content: Iterable[bytes] = ..., *args: Any, **kwargs: Any) -> None: ...
|
||||||
def getvalue(self) -> bytes: ...
|
def getvalue(self) -> bytes: ...
|
||||||
|
|
||||||
class FileResponse(StreamingHttpResponse):
|
class FileResponse(StreamingHttpResponse):
|
||||||
|
|||||||
Reference in New Issue
Block a user