Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.0: Update django.core.handlers #2066

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion django-stubs/core/handlers/asgi.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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: ...
5 changes: 5 additions & 0 deletions django-stubs/core/handlers/base.pyi
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def reset_urlconf(sender: object, **kwargs: Any) -> None: ...
import _typeshed
def reset_urlconf(sender: _typeshed.Unused, **kwargs: Any) -> None: ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I didn't know that feature :) dc3b266

14 changes: 4 additions & 10 deletions django-stubs/core/handlers/wsgi.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down
6 changes: 0 additions & 6 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions scripts/stubtest/allowlist_todo_django50.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.serializers.base.PickleSerializer
django.db.backends.base.features.BaseDatabaseFeatures.delete_can_self_reference_subquery
django.db.backends.base.features.BaseDatabaseFeatures.insert_test_table_with_defaults
Expand Down
Loading