]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
pyright lint for async backends
authorBob Halley <halley@dnspython.org>
Wed, 16 Oct 2024 01:14:45 +0000 (18:14 -0700)
committerBob Halley <halley@dnspython.org>
Wed, 16 Oct 2024 01:14:45 +0000 (18:14 -0700)
dns/_asyncbackend.py
dns/_asyncio_backend.py
dns/_trio_backend.py
pyproject.toml

index f6760fd0da90f1f000ba45631ee5ae9ef13cf78d..23455db37403f201c22bea60e59afb0438d59fdb 100644 (file)
@@ -71,7 +71,7 @@ class NullTransport:
 
 
 class Backend:  # pragma: no cover
-    def name(self):
+    def name(self) -> str:
         return "unknown"
 
     async def make_socket(
index 6ab168de543892770055eb8412bf3de80edb046c..99656d4467a373e7ae36f4fe84048ce3a580e807 100644 (file)
@@ -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,
index 0ed904ddcf13a544630c3bd1b8176d50cba32a98..bde7e8bab226942aa23681824579eef29d8bb069 100644 (file)
@@ -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:
index 2c78aad0c59fa94b1c7be168bd1ba6c375304d9c..d7d72e101a75de8eef7d4bb3324a6a38f56e8c8a 100644 (file)
@@ -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!