From 66d48a1eeb74f33499b1d1034861585bad88bdcc Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Tue, 21 Jun 2022 20:33:29 +0200 Subject: [PATCH] Add missing string annotations --- uvicorn/middleware/message_logger.py | 2 +- uvicorn/middleware/proxy_headers.py | 2 +- uvicorn/middleware/wsgi.py | 5 ++++- uvicorn/protocols/http/h11_impl.py | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/uvicorn/middleware/message_logger.py b/uvicorn/middleware/message_logger.py index 695a32626..4738e0752 100644 --- a/uvicorn/middleware/message_logger.py +++ b/uvicorn/middleware/message_logger.py @@ -58,7 +58,7 @@ async def __call__( client = scope.get("client") prefix = "%s:%d - ASGI" % (client[0], client[1]) if client else "ASGI" - async def inner_receive() -> ASGIReceiveEvent: + async def inner_receive() -> "ASGIReceiveEvent": message = await receive() logged_message = message_with_placeholders(message) log_text = "%s [%d] Receive %s" diff --git a/uvicorn/middleware/proxy_headers.py b/uvicorn/middleware/proxy_headers.py index ff090cf2f..4b62cf209 100644 --- a/uvicorn/middleware/proxy_headers.py +++ b/uvicorn/middleware/proxy_headers.py @@ -50,7 +50,7 @@ async def __call__( self, scope: "Scope", receive: "ASGIReceiveCallable", send: "ASGISendCallable" ) -> None: if scope["type"] in ("http", "websocket"): - scope = cast(Union[HTTPScope, WebSocketScope], scope) + scope = cast(Union["HTTPScope", "WebSocketScope"], scope) client_addr: Optional[Tuple[str, int]] = scope.get("client") client_host = client_addr[0] if client_addr else None diff --git a/uvicorn/middleware/wsgi.py b/uvicorn/middleware/wsgi.py index e9f7fa188..9a79a3baf 100644 --- a/uvicorn/middleware/wsgi.py +++ b/uvicorn/middleware/wsgi.py @@ -79,7 +79,10 @@ def __init__(self, app: WSGIApp, workers: int = 10): self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=workers) async def __call__( - self, scope: HTTPScope, receive: ASGIReceiveCallable, send: ASGISendCallable + self, + scope: "HTTPScope", + receive: "ASGIReceiveCallable", + send: "ASGISendCallable", ) -> None: assert scope["type"] == "http" instance = WSGIResponder(self.app, self.executor, scope) diff --git a/uvicorn/protocols/http/h11_impl.py b/uvicorn/protocols/http/h11_impl.py index b7550dde8..a9632c6ea 100644 --- a/uvicorn/protocols/http/h11_impl.py +++ b/uvicorn/protocols/http/h11_impl.py @@ -493,7 +493,7 @@ async def send(self, message: "ASGISendEvent") -> None: if message_type != "http.response.body": msg = "Expected ASGI message 'http.response.body', but got '%s'." raise RuntimeError(msg % message_type) - message = cast(HTTPResponseBodyEvent, message) + message = cast("HTTPResponseBodyEvent", message) body = message.get("body", b"") more_body = message.get("more_body", False)