From 192ac4e988d3cd38703153d6d5a3879896500f83 Mon Sep 17 00:00:00 2001 From: Moriyoshi Koizumi Date: Thu, 15 Oct 2020 05:51:28 +0900 Subject: [PATCH] Add type: ignore for aiofiles to make mypy happier (#1072) * Add type: ignore to make mypy happier * Tentatively ignore type checking failure until the following patch gets merged https://github.com/python/typeshed/pull/4650 --- starlette/responses.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/starlette/responses.py b/starlette/responses.py index 24dfb2c84..24e3b5469 100644 --- a/starlette/responses.py +++ b/starlette/responses.py @@ -22,8 +22,8 @@ import aiofiles from aiofiles.os import stat as aio_stat except ImportError: # pragma: nocover - aiofiles = None - aio_stat = None + aiofiles = None # type: ignore + aio_stat = None # type: ignore try: import ujson @@ -312,7 +312,10 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: if self.send_header_only: await send({"type": "http.response.body", "body": b"", "more_body": False}) else: - async with aiofiles.open(self.path, mode="rb") as file: + # Tentatively ignoring type checking failure to work around the wrong type + # definitions for aiofile that come with typeshed. See + # https://github.com/python/typeshed/pull/4650 + async with aiofiles.open(self.path, mode="rb") as file: # type: ignore more_body = True while more_body: chunk = await file.read(self.chunk_size)