[gunicorn] Add precise return type for asgi.protocol:BodyReceiver.receive (#15567)

This commit is contained in:
lev-blit
2026-03-30 13:37:51 +03:00
committed by GitHub
parent 5e99fcf870
commit 9023424987
+9 -3
View File
@@ -1,7 +1,7 @@
import asyncio
from _typeshed import Incomplete
from collections.abc import Iterable
from typing import Final
from typing import Final, Literal, TypedDict, type_check_only
from typing_extensions import NotRequired
from gunicorn.asgi.parser import CallbackRequest
from gunicorn.config import Config
@@ -31,6 +31,12 @@ class ASGIResponseInfo:
def __init__(self, status: str | int, headers: Iterable[tuple[str | bytes, str | bytes]], sent: int) -> None: ...
@type_check_only
class _BodyReceieverReceiveReturnType(TypedDict):
type: Literal["http.disconnect", "http.request"]
body: NotRequired[bytes]
more_body: NotRequired[bool]
class BodyReceiver:
__slots__ = ("_chunks", "_complete", "_body_finished", "_closed", "_waiter", "request", "protocol")
request: CallbackRequest
@@ -40,7 +46,7 @@ class BodyReceiver:
def feed(self, chunk: bytes) -> None: ...
def set_complete(self) -> None: ...
def signal_disconnect(self) -> None: ...
async def receive(self) -> dict[str, Incomplete]: ... # TODO: Use TypedDict
async def receive(self) -> _BodyReceieverReceiveReturnType: ...
class ASGIProtocol(asyncio.Protocol):
worker: ASGIWorker