diff --git a/dns/_asyncbackend.py b/dns/_asyncbackend.py index f6760fd0..23455db3 100644 --- a/dns/_asyncbackend.py +++ b/dns/_asyncbackend.py @@ -71,7 +71,7 @@ async def connect_tcp(self, host, port, timeout, local_address): class Backend: # pragma: no cover - def name(self): + def name(self) -> str: return "unknown" async def make_socket( diff --git a/dns/_asyncio_backend.py b/dns/_asyncio_backend.py index 6ab168de..99656d44 100644 --- a/dns/_asyncio_backend.py +++ b/dns/_asyncio_backend.py @@ -49,7 +49,8 @@ def connection_lost(self, exc): self.recvfrom.set_exception(exc) def close(self): - self.transport.close() + if self.transport is not None: + self.transport.close() async def _maybe_wait_for(awaitable, timeout): @@ -147,7 +148,7 @@ def __init__(self, resolver, local_port, bootstrap_address, family): ) async def connect_tcp( - self, host, port, timeout, local_address, socket_options=None + self, host, port, timeout=None, local_address=None, socket_options=None ): # pylint: disable=signature-differs addresses = [] _, expiration = _compute_times(timeout) @@ -180,7 +181,7 @@ async def connect_tcp( raise httpcore.ConnectError async def connect_unix_socket( - self, path, timeout, socket_options=None + self, path, timeout=None, socket_options=None ): # pylint: disable=signature-differs raise NotImplementedError @@ -233,7 +234,7 @@ async def make_socket( # proper fix for [#637]. source = (dns.inet.any_for_af(af), 0) transport, protocol = await loop.create_datagram_endpoint( - _DatagramProtocol, + _DatagramProtocol, # pyright: ignore source, family=af, proto=proto, diff --git a/dns/_trio_backend.py b/dns/_trio_backend.py index 0ed904dd..bde7e8ba 100644 --- a/dns/_trio_backend.py +++ b/dns/_trio_backend.py @@ -121,7 +121,7 @@ def __init__(self, resolver, local_port, bootstrap_address, family): self._family = family async def connect_tcp( - self, host, port, timeout, local_address, socket_options=None + self, host, port, timeout=None, local_address=None, socket_options=None ): # pylint: disable=signature-differs addresses = [] _, expiration = _compute_times(timeout) @@ -151,13 +151,14 @@ async def connect_tcp( sock = await Backend().make_socket( af, socket.SOCK_STREAM, 0, source, destination, timeout ) + assert isinstance(sock, StreamSocket) return _CoreTrioStream(sock.stream) except Exception: continue raise httpcore.ConnectError async def connect_unix_socket( - self, path, timeout, socket_options=None + self, path, timeout=None, socket_options=None ): # pylint: disable=signature-differs raise NotImplementedError @@ -211,6 +212,7 @@ async def make_socket( if socktype == socket.SOCK_STREAM or destination is not None: connected = False with _maybe_timeout(timeout): + assert destination is not None await s.connect(_lltuple(destination, af)) connected = True if not connected: diff --git a/pyproject.toml b/pyproject.toml index 2c78aad0..d7d72e10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -119,9 +119,4 @@ ignore_missing_imports = true [tool.pyright] reportUnsupportedDunderAll = false -exclude = [ - "dns/_*_backend.py", - "dns/quic/*.py", - "examples/*.py", - "tests/*.py", -] # (mostly) temporary! +exclude = ["dns/quic/*.py", "examples/*.py", "tests/*.py"] # (mostly) temporary!