Skip to content

Commit 9023424

Browse files
authored
[gunicorn] Add precise return type for asgi.protocol:BodyReceiver.receive (#15567)
1 parent 5e99fcf commit 9023424

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

stubs/gunicorn/gunicorn/asgi/protocol.pyi

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
2-
from _typeshed import Incomplete
32
from collections.abc import Iterable
4-
from typing import Final
3+
from typing import Final, Literal, TypedDict, type_check_only
4+
from typing_extensions import NotRequired
55

66
from gunicorn.asgi.parser import CallbackRequest
77
from gunicorn.config import Config
@@ -31,6 +31,12 @@ class ASGIResponseInfo:
3131

3232
def __init__(self, status: str | int, headers: Iterable[tuple[str | bytes, str | bytes]], sent: int) -> None: ...
3333

34+
@type_check_only
35+
class _BodyReceieverReceiveReturnType(TypedDict):
36+
type: Literal["http.disconnect", "http.request"]
37+
body: NotRequired[bytes]
38+
more_body: NotRequired[bool]
39+
3440
class BodyReceiver:
3541
__slots__ = ("_chunks", "_complete", "_body_finished", "_closed", "_waiter", "request", "protocol")
3642
request: CallbackRequest
@@ -40,7 +46,7 @@ class BodyReceiver:
4046
def feed(self, chunk: bytes) -> None: ...
4147
def set_complete(self) -> None: ...
4248
def signal_disconnect(self) -> None: ...
43-
async def receive(self) -> dict[str, Incomplete]: ... # TODO: Use TypedDict
49+
async def receive(self) -> _BodyReceieverReceiveReturnType: ...
4450

4551
class ASGIProtocol(asyncio.Protocol):
4652
worker: ASGIWorker

0 commit comments

Comments
 (0)