From 65f8d9b2a3e8da6e4bde0f368cde0705ecd717ce Mon Sep 17 00:00:00 2001 From: Lev Blit Date: Sat, 28 Mar 2026 01:32:08 +0300 Subject: [PATCH] [gunicorn]: add return type for asgi.protocol:BodyReceiver.receive --- stubs/gunicorn/gunicorn/asgi/protocol.pyi | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stubs/gunicorn/gunicorn/asgi/protocol.pyi b/stubs/gunicorn/gunicorn/asgi/protocol.pyi index 282ee41f5a8a..664c64d68db1 100644 --- a/stubs/gunicorn/gunicorn/asgi/protocol.pyi +++ b/stubs/gunicorn/gunicorn/asgi/protocol.pyi @@ -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