Skip to content

Commit

Permalink
Fix mypy?
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Nov 21, 2023
1 parent 3122ad0 commit f557d9c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/hypercorn/app_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def start_response(
for name, value in response_headers
]

def send_headers(content_length: int):
def send_headers(content_length: int) -> None:
nonlocal headers, headers_sent
if not headers:
raise AssertionError("missing call to start_response")
Expand All @@ -115,7 +115,7 @@ def send_headers(content_length: int):
send({"type": "http.response.start", "status": status_code, "headers": headers})
headers_sent = True

def send_body(data: bytes = b"", more_body: bool = False):
def send_body(data: bytes = b"", more_body: bool = False) -> None:
if not headers_sent:
send_headers(len(data))
send({"type": "http.response.body", "body": data, "more_body": more_body})
Expand All @@ -124,7 +124,7 @@ def send_body(data: bytes = b"", more_body: bool = False):

body_part_count: Optional[int] = None
if hasattr(response_body, "__len__"):
body_part_count = len(response_body)
body_part_count = len(response_body) # type: ignore

try:
# Optimize the common case of one body part
Expand Down
1 change: 1 addition & 0 deletions src/hypercorn/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class LifespanShutdownFailedEvent(TypedDict):
],
Awaitable[None],
]
# TODO: Iterable[bytes] is not really the correct return type as it misses .close()/.__len__()
WSGIFramework = Callable[[dict, Callable], Iterable[bytes]]
Framework = Union[ASGIFramework, WSGIFramework]

Expand Down
8 changes: 5 additions & 3 deletions tests/test_app_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import asyncio
from functools import partial
from typing import Any, Callable, Iterable, List
from typing import Any, Callable, Iterable, List, Self

import pytest
import trio
Expand All @@ -27,7 +27,7 @@ class ResponseHelperBase:
def __init__(self, body_parts: list[bytes] = []):
self.body_parts = iter(body_parts)

def __iter__(self):
def __iter__(self) -> Self:
return self

def __next__(self) -> bytes:
Expand Down Expand Up @@ -58,7 +58,9 @@ def app(environ: dict, start_response: Callable) -> Iterable[bytes]:
return app


async def wsgi_helper(wsgi_app: WSGIFramework, event_loop: asyncio.AbstractEventLoop) -> list[dict]:
async def wsgi_helper(
wsgi_app: WSGIFramework, event_loop: asyncio.AbstractEventLoop
) -> list[ASGISendEvent]:
app = WSGIWrapper(wsgi_app, 2**16)
scope: HTTPScope = {
"http_version": "1.1",
Expand Down

0 comments on commit f557d9c

Please sign in to comment.