From e8a7e2032842840ce2d3492b49b75c523feadaa6 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Tue, 15 Oct 2024 18:14:45 -0700 Subject: [PATCH] pyright lint for async backends --- dns/_asyncbackend.py | 2 +- dns/_asyncio_backend.py | 9 +++++---- dns/_trio_backend.py | 6 ++++-- pyproject.toml | 7 +------ 4 files changed, 11 insertions(+), 13 deletions(-) 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 @@ class NullTransport: 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 @@ class _DatagramProtocol: 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 @@ if dns._features.have("doh"): ) 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 @@ if dns._features.have("doh"): 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 @@ class Backend(dns._asyncbackend.Backend): # 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 @@ if dns._features.have("doh"): 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 @@ if dns._features.have("doh"): 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 @@ class Backend(dns._asyncbackend.Backend): 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! -- 2.47.3