]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Typing: enable disallow_incomplete_defs (#2476)
authorMartijn Pieters <mj@zopatista.com>
Wed, 30 Nov 2022 09:04:54 +0000 (09:04 +0000)
committerGitHub <noreply@github.com>
Wed, 30 Nov 2022 09:04:54 +0000 (09:04 +0000)
The only places mypy reports issues is in the test suite.

setup.cfg
tests/client/test_proxies.py
tests/conftest.py
tests/test_content.py
tests/test_exceptions.py
tests/test_multipart.py
tests/test_wsgi.py
tests/utils.py

index 3e2a335750acaeb4b1d3fd056502035721e0018a..c7d43f0c0fa24e9366fd08e7603b973d282c77b4 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -15,6 +15,7 @@ check_untyped_defs = True
 disallow_untyped_decorators = True
 warn_redundant_casts = True
 strict_concatenate = True
+disallow_incomplete_defs = True
 
 [mypy-tests.*]
 disallow_untyped_defs = False
index c44cb54aa09d9f00c1adcd700de4c8aa09197b1d..98dfafab26379c3d8c3a2169809e110d63a1321c 100644 (file)
@@ -5,7 +5,7 @@ import httpx
 from httpx._utils import URLPattern
 
 
-def url_to_origin(url: str):
+def url_to_origin(url: str) -> httpcore.URL:
     """
     Given a URL string, return the origin in the raw tuple format that
     `httpcore` uses for it's representation.
index 0d39e41bdc01b3f1911afe88b3bedd9349680314..6dbb5267f31ae5678ffe398cae44a0fb5a12934a 100644 (file)
@@ -290,7 +290,7 @@ class TestServer(Server):
             await self.startup()
 
 
-def serve_in_thread(server: Server):
+def serve_in_thread(server: TestServer) -> typing.Iterator[TestServer]:
     thread = threading.Thread(target=server.run)
     thread.start()
     try:
@@ -303,7 +303,7 @@ def serve_in_thread(server: Server):
 
 
 @pytest.fixture(scope="session")
-def server():
+def server() -> typing.Iterator[TestServer]:
     config = Config(app=app, lifespan="off", loop="asyncio")
     server = TestServer(config=config)
     yield from serve_in_thread(server)
index 7b13090b1e1113ec2aa1029587ac6568aec73c85..73220b2fe7f0c43f2232cad06583d866f5a97e3b 100644 (file)
@@ -67,7 +67,7 @@ async def test_async_bytesio_content():
             self._idx = 0
             self._content = content
 
-        async def aread(self, chunk_size: int):
+        async def aread(self, chunk_size: int) -> bytes:
             chunk = self._content[self._idx : self._idx + chunk_size]
             self._idx = self._idx + chunk_size
             return chunk
index 7d2de24b50f0743f78b8bf1c9d54188804dccd97..b765d46a2d8916763394b93fc0213d4c32f48c88 100644 (file)
@@ -1,3 +1,4 @@
+import typing
 from unittest import mock
 
 import httpcore
@@ -6,6 +7,9 @@ import pytest
 import httpx
 from httpx._transports.default import HTTPCORE_EXC_MAP
 
+if typing.TYPE_CHECKING:  # pragma: no cover
+    from conftest import TestServer
+
 
 def test_httpcore_all_exceptions_mapped() -> None:
     """
@@ -25,7 +29,7 @@ def test_httpcore_all_exceptions_mapped() -> None:
         pytest.fail(f"Unmapped httpcore exceptions: {not_mapped}")
 
 
-def test_httpcore_exception_mapping(server) -> None:
+def test_httpcore_exception_mapping(server: "TestServer") -> None:
     """
     HTTPCore exception mapping works as expected.
     """
index 80b4588c69179e4a7c90c2317269a33fdfa40312..e9ce928a16855e7b9dcce55011abe4df067946cc 100644 (file)
@@ -152,7 +152,7 @@ def test_multipart_file_tuple():
 
 
 @pytest.mark.parametrize("content_type", [None, "text/plain"])
-def test_multipart_file_tuple_headers(content_type: typing.Optional[str]):
+def test_multipart_file_tuple_headers(content_type: typing.Optional[str]) -> None:
     file_name = "test.txt"
     expected_content_type = "text/plain"
     headers = {"Expires": "0"}
index 0eeb32d145a09574cde20766200161a784972ad2..c1439d7bcd713f06ab4d7613bb15cf6619ce0043 100644 (file)
@@ -144,7 +144,7 @@ def test_logging():
         pytest.param("http://www.example.org:8000", "8000", id="explicit-port"),
     ],
 )
-def test_wsgi_server_port(url: str, expected_server_port: int):
+def test_wsgi_server_port(url: str, expected_server_port: int) -> None:
     """
     SERVER_PORT is populated correctly from the requested URL.
     """
index e2636a535cfb5ac2dcc96fb3cfd974ae7ada134a..96bd05d621f0c131117b748d43da0f4929be8382 100644 (file)
@@ -1,12 +1,13 @@
 import contextlib
 import logging
 import os
+import typing
 
 from httpx import _utils
 
 
 @contextlib.contextmanager
-def override_log_level(log_level: str):
+def override_log_level(log_level: str) -> typing.Iterator[None]:
     os.environ["HTTPX_LOG_LEVEL"] = log_level
 
     # Force a reload on the logging handlers