Typing: enable disallow_incomplete_defs (#2476)

The only places mypy reports issues is in the test suite.
This commit is contained in:
Martijn Pieters 2022-11-30 09:04:54 +00:00 committed by GitHub
parent 1ff67ea47c
commit 049afe5b25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 8 deletions

View File

@ -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

View 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.

View 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)

View 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

View 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.
"""

View 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"}

View 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.
"""

View 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