From: Martijn Pieters Date: Wed, 30 Nov 2022 13:08:02 +0000 (+0000) Subject: Typing: enable warn_return_any (#2477) X-Git-Tag: 0.23.2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d37321842c566b1fd81f9627ab4072064286d16;p=thirdparty%2Fhttpx.git Typing: enable warn_return_any (#2477) --- diff --git a/httpx/_decoders.py b/httpx/_decoders.py index ba7b81d1..2f3a447d 100644 --- a/httpx/_decoders.py +++ b/httpx/_decoders.py @@ -104,6 +104,7 @@ class BrotliDecoder(ContentDecoder): self.decompressor = brotli.Decompressor() self.seen_data = False + self._decompress: typing.Callable[[bytes], bytes] if hasattr(self.decompressor, "decompress"): # The 'brotlicffi' package. self._decompress = self.decompressor.decompress # pragma: no cover diff --git a/httpx/_main.py b/httpx/_main.py index ba79c69e..7c12ce84 100644 --- a/httpx/_main.py +++ b/httpx/_main.py @@ -100,7 +100,9 @@ def get_lexer_for_response(response: Response) -> str: if content_type is not None: mime_type, _, _ = content_type.partition(";") try: - return pygments.lexers.get_lexer_for_mimetype(mime_type.strip()).name + return typing.cast( + str, pygments.lexers.get_lexer_for_mimetype(mime_type.strip()).name + ) except pygments.util.ClassNotFound: # pragma: no cover pass return "" # pragma: no cover diff --git a/httpx/_models.py b/httpx/_models.py index e3370369..e0e5278c 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -540,16 +540,20 @@ class Response: @property def http_version(self) -> str: try: - return self.extensions["http_version"].decode("ascii", errors="ignore") + http_version: bytes = self.extensions["http_version"] except KeyError: return "HTTP/1.1" + else: + return http_version.decode("ascii", errors="ignore") @property def reason_phrase(self) -> str: try: - return self.extensions["reason_phrase"].decode("ascii", errors="ignore") + reason_phrase: bytes = self.extensions["reason_phrase"] except KeyError: return codes.get_reason_phrase(self.status_code) + else: + return reason_phrase.decode("ascii", errors="ignore") @property def url(self) -> URL: diff --git a/httpx/_urls.py b/httpx/_urls.py index 05db1652..ab39c2ec 100644 --- a/httpx/_urls.py +++ b/httpx/_urls.py @@ -70,6 +70,8 @@ class URL: be properly URL escaped when decoding the parameter names and values themselves. """ + _uri_reference: rfc3986.URIReference + def __init__( self, url: typing.Union["URL", str] = "", **kwargs: typing.Any ) -> None: @@ -507,7 +509,7 @@ class URL: return isinstance(other, (URL, str)) and str(self) == str(URL(other)) def __str__(self) -> str: - return self._uri_reference.unsplit() + return typing.cast(str, self._uri_reference.unsplit()) def __repr__(self) -> str: class_name = self.__class__.__name__ diff --git a/httpx/_utils.py b/httpx/_utils.py index 01eaaced..c1e9a38b 100644 --- a/httpx/_utils.py +++ b/httpx/_utils.py @@ -401,7 +401,7 @@ class Timer: elif library == "curio": # pragma: no cover import curio - return await curio.clock() + return typing.cast(float, await curio.clock()) import asyncio diff --git a/setup.cfg b/setup.cfg index c7d43f0c..15dd84c2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,6 +16,7 @@ disallow_untyped_decorators = True warn_redundant_casts = True strict_concatenate = True disallow_incomplete_defs = True +warn_return_any = True [mypy-tests.*] disallow_untyped_defs = False diff --git a/tests/conftest.py b/tests/conftest.py index 6dbb5267..cb4bf422 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -52,7 +52,7 @@ def async_environment(request: typing.Any) -> str: ... ``` """ - return request.param + return typing.cast(str, request.param) @pytest.fixture(scope="function", autouse=True) diff --git a/tests/test_content.py b/tests/test_content.py index 73220b2f..61d0c71e 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -63,7 +63,7 @@ async def test_bytesio_content(): @pytest.mark.asyncio async def test_async_bytesio_content(): class AsyncBytesIO: - def __init__(self, content): + def __init__(self, content: bytes): self._idx = 0 self._content = content