The only places mypy reports issues is in the test suite.
disallow_untyped_decorators = True
warn_redundant_casts = True
strict_concatenate = True
+disallow_incomplete_defs = True
[mypy-tests.*]
disallow_untyped_defs = False
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.
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:
@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)
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
+import typing
from unittest import mock
import httpcore
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:
"""
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.
"""
@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"}
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.
"""
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