From 1c3be988fe4e6d565acb00c68045fcf927fed62c Mon Sep 17 00:00:00 2001 From: sudosubin Date: Tue, 16 Apr 2024 01:18:51 +0900 Subject: [PATCH 1/2] 5.0: Update `django.core.handlers` --- django-stubs/core/handlers/asgi.pyi | 11 ++++++++++- django-stubs/core/handlers/base.pyi | 5 +++++ django-stubs/core/handlers/wsgi.pyi | 14 ++++---------- scripts/stubtest/allowlist_todo.txt | 6 ------ scripts/stubtest/allowlist_todo_django50.txt | 4 ---- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/django-stubs/core/handlers/asgi.pyi b/django-stubs/core/handlers/asgi.pyi index aaf235ce2..f260cc714 100644 --- a/django-stubs/core/handlers/asgi.pyi +++ b/django-stubs/core/handlers/asgi.pyi @@ -1,4 +1,5 @@ from collections.abc import Awaitable, Callable, Iterator, Mapping, Sequence +from logging import Logger from typing import IO, Any, TypeVar from django.core.handlers import base @@ -13,6 +14,10 @@ _ReceiveCallback: TypeAlias = Callable[[], Awaitable[Mapping[str, Any]]] _SendCallback: TypeAlias = Callable[[Mapping[str, Any]], Awaitable[None]] +logger: Logger + +def get_script_prefix(scope: Mapping[str, Any]) -> str: ... + class ASGIRequest(HttpRequest): body_receive_timeout: int scope: Mapping[str, Any] @@ -42,6 +47,11 @@ class ASGIHandler(base.BaseHandler): receive: _ReceiveCallback, send: _SendCallback, ) -> None: ... + async def handle( + self, scope: dict[str, Any], receive: _ReceiveCallback, send: _SendCallback + ) -> HttpResponseBase | None: ... + async def listen_for_disconnect(self, receive: _ReceiveCallback) -> None: ... + async def run_get_response(self, request: HttpRequest) -> HttpResponseBase: ... async def read_body(self, receive: _ReceiveCallback) -> IO[bytes]: ... def create_request( self, scope: Mapping[str, Any], body_file: IO[bytes] @@ -52,4 +62,3 @@ class ASGIHandler(base.BaseHandler): async def send_response(self, response: HttpResponseBase, send: _SendCallback) -> None: ... @classmethod def chunk_bytes(cls, data: Sequence[_T]) -> Iterator[tuple[Sequence[_T], bool]]: ... - def get_script_prefix(self, scope: Mapping[str, Any]) -> str: ... diff --git a/django-stubs/core/handlers/base.pyi b/django-stubs/core/handlers/base.pyi index 011722786..ce4fcfa5d 100644 --- a/django-stubs/core/handlers/base.pyi +++ b/django-stubs/core/handlers/base.pyi @@ -1,10 +1,13 @@ from collections.abc import Awaitable, Callable +from logging import Logger from typing import Any from django.http.request import HttpRequest from django.http.response import HttpResponse, HttpResponseBase from django.urls.resolvers import ResolverMatch +logger: Logger + class BaseHandler: def load_middleware(self, is_async: bool = ...) -> None: ... def adapt_method_mode( @@ -21,3 +24,5 @@ class BaseHandler: def check_response(self, response: HttpResponseBase, callback: Any, name: str | None = ...) -> None: ... def make_view_atomic(self, view: Callable[..., HttpResponseBase]) -> Callable[..., HttpResponseBase]: ... def process_exception_by_middleware(self, exception: Exception, request: HttpRequest) -> HttpResponse: ... + +def reset_urlconf(sender: object, **kwargs: Any) -> None: ... diff --git a/django-stubs/core/handlers/wsgi.pyi b/django-stubs/core/handlers/wsgi.pyi index 9fd928b09..435df0792 100644 --- a/django-stubs/core/handlers/wsgi.pyi +++ b/django-stubs/core/handlers/wsgi.pyi @@ -1,8 +1,7 @@ import sys -from io import BytesIO +from io import BytesIO, IOBase from typing import Any -from django.contrib.sessions.backends.base import SessionBase from django.core.handlers import base from django.http import HttpRequest from django.http.response import HttpResponseBase @@ -12,19 +11,14 @@ if sys.version_info >= (3, 11): else: from _typeshed.wsgi import StartResponse, WSGIEnvironment -class LimitedStream: - stream: BytesIO - remaining: int - buffer: bytes - buf_size: int - def __init__(self, stream: BytesIO, limit: int, buf_size: int = ...) -> None: ... +class LimitedStream(IOBase): + limit: int + def __init__(self, stream: BytesIO, limit: int) -> None: ... def read(self, size: int | None = ...) -> bytes: ... def readline(self, size: int | None = ...) -> bytes: ... class WSGIRequest(HttpRequest): environ: WSGIEnvironment - session: SessionBase - encoding: Any def __init__(self, environ: WSGIEnvironment) -> None: ... class WSGIHandler(base.BaseHandler): diff --git a/scripts/stubtest/allowlist_todo.txt b/scripts/stubtest/allowlist_todo.txt index 97a187557..73cc32c64 100644 --- a/scripts/stubtest/allowlist_todo.txt +++ b/scripts/stubtest/allowlist_todo.txt @@ -658,13 +658,7 @@ django.core.files.utils.FileProxyMixin.tell django.core.files.utils.FileProxyMixin.truncate django.core.files.utils.FileProxyMixin.write django.core.files.utils.FileProxyMixin.writelines -django.core.handlers.asgi.ASGIHandler.handle django.core.handlers.asgi.ASGIRequest.FILES -django.core.handlers.asgi.logger -django.core.handlers.base.logger -django.core.handlers.base.reset_urlconf -django.core.handlers.wsgi.LimitedStream -django.core.handlers.wsgi.LimitedStream.__init__ django.core.handlers.wsgi.WSGIRequest.COOKIES django.core.handlers.wsgi.WSGIRequest.FILES django.core.handlers.wsgi.WSGIRequest.GET diff --git a/scripts/stubtest/allowlist_todo_django50.txt b/scripts/stubtest/allowlist_todo_django50.txt index 0de61f3dd..098774ef5 100644 --- a/scripts/stubtest/allowlist_todo_django50.txt +++ b/scripts/stubtest/allowlist_todo_django50.txt @@ -57,10 +57,6 @@ django.contrib.sites.migrations.0001_initial django.contrib.sites.migrations.0002_alter_domain_unique django.contrib.staticfiles.checks.E005 django.contrib.staticfiles.checks.check_storages -django.core.handlers.asgi.ASGIHandler.get_script_prefix -django.core.handlers.asgi.ASGIHandler.listen_for_disconnect -django.core.handlers.asgi.ASGIHandler.run_get_response -django.core.handlers.asgi.get_script_prefix django.core.management.commands.inspectdb.Command.normalize_table_name django.core.management.commands.optimizemigration django.core.serializers.base.PickleSerializer From dc3b2666ab1fa34ccbce7671ec3c29ed6007e23b Mon Sep 17 00:00:00 2001 From: sudosubin Date: Wed, 17 Apr 2024 00:31:02 +0900 Subject: [PATCH 2/2] 5.0: Update unused argument type --- django-stubs/core/handlers/base.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/django-stubs/core/handlers/base.pyi b/django-stubs/core/handlers/base.pyi index ce4fcfa5d..ee36a3cc1 100644 --- a/django-stubs/core/handlers/base.pyi +++ b/django-stubs/core/handlers/base.pyi @@ -2,6 +2,7 @@ from collections.abc import Awaitable, Callable from logging import Logger from typing import Any +import _typeshed from django.http.request import HttpRequest from django.http.response import HttpResponse, HttpResponseBase from django.urls.resolvers import ResolverMatch @@ -25,4 +26,4 @@ class BaseHandler: def make_view_atomic(self, view: Callable[..., HttpResponseBase]) -> Callable[..., HttpResponseBase]: ... def process_exception_by_middleware(self, exception: Exception, request: HttpRequest) -> HttpResponse: ... -def reset_urlconf(sender: object, **kwargs: Any) -> None: ... +def reset_urlconf(sender: _typeshed.Unused, **kwargs: Any) -> None: ...