From: Amin Alaee Date: Fri, 14 Jan 2022 13:30:46 +0000 (+0100) Subject: Use typing `NoReturn` (#1412) X-Git-Tag: 0.18.0~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fcc4c705ff69182ebd663bc686cb55c242d32683;p=thirdparty%2Fstarlette.git Use typing `NoReturn` (#1412) --- diff --git a/requirements.txt b/requirements.txt index 48f3cfa3..51389304 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ coverage==6.2 databases[sqlite]==0.5.3 flake8==4.0.1 isort==5.10.1 -mypy==0.930 +mypy==0.931 types-requests==2.26.3 types-contextvars==2.4.0 types-PyYAML==6.0.1 diff --git a/starlette/datastructures.py b/starlette/datastructures.py index 52904d51..2c5c4b01 100644 --- a/starlette/datastructures.py +++ b/starlette/datastructures.py @@ -163,7 +163,7 @@ class URLPath(str): def __new__(cls, path: str, protocol: str = "", host: str = "") -> "URLPath": assert protocol in ("http", "websocket", "") - return str.__new__(cls, path) # type: ignore + return str.__new__(cls, path) def __init__(self, path: str, protocol: str = "", host: str = "") -> None: self.protocol = protocol @@ -441,7 +441,7 @@ class UploadFile: async def write(self, data: bytes) -> None: if self._in_memory: - self.file.write(data) # type: ignore + self.file.write(data) else: await run_in_threadpool(self.file.write, data) diff --git a/starlette/middleware/gzip.py b/starlette/middleware/gzip.py index 37c6936f..9d69ee7c 100644 --- a/starlette/middleware/gzip.py +++ b/starlette/middleware/gzip.py @@ -1,5 +1,6 @@ import gzip import io +import typing from starlette.datastructures import Headers, MutableHeaders from starlette.types import ASGIApp, Message, Receive, Scope, Send @@ -100,5 +101,5 @@ class GZipResponder: await self.send(message) -async def unattached_send(message: Message) -> None: +async def unattached_send(message: Message) -> typing.NoReturn: raise RuntimeError("send awaitable not set") # pragma: no cover diff --git a/starlette/requests.py b/starlette/requests.py index cf129702..a33367e1 100644 --- a/starlette/requests.py +++ b/starlette/requests.py @@ -51,7 +51,7 @@ def cookie_parser(cookie_string: str) -> typing.Dict[str, str]: key, val = key.strip(), val.strip() if key or val: # unquote using Python's algorithm. - cookie_dict[key] = http_cookies._unquote(val) # type: ignore + cookie_dict[key] = http_cookies._unquote(val) return cookie_dict @@ -175,11 +175,11 @@ class HTTPConnection(Mapping): return url_path.make_absolute_url(base_url=self.base_url) -async def empty_receive() -> Message: +async def empty_receive() -> typing.NoReturn: raise RuntimeError("Receive channel has not been made available") -async def empty_send(message: Message) -> None: +async def empty_send(message: Message) -> typing.NoReturn: raise RuntimeError("Send channel has not been made available")