From: Bob Halley Date: Sat, 6 Dec 2025 22:46:42 +0000 (-0800) Subject: more ty fixes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8517b50c34d78f460408165ec1ec8c4e3cc4e986;p=thirdparty%2Fdnspython.git more ty fixes --- diff --git a/dns/asyncquery.py b/dns/asyncquery.py index b5e58540..36905a20 100644 --- a/dns/asyncquery.py +++ b/dns/asyncquery.py @@ -731,10 +731,10 @@ async def _http3( wire = q.to_wire() the_connection: dns.quic.AsyncQuicConnection if connection: - cfactory = dns.quic.null_factory - mfactory = dns.quic.null_factory + cfactory = dns.quic.null_factory # type: ignore + mfactory = dns.quic.null_factory # type: ignore else: - (cfactory, mfactory) = dns.quic.factories_for_backend(backend) + (cfactory, mfactory) = dns.quic.factories_for_backend(backend) # type: ignore async with cfactory() as context: async with mfactory( @@ -802,11 +802,11 @@ async def quic( wire = q.to_wire() the_connection: dns.quic.AsyncQuicConnection if connection: - cfactory = dns.quic.null_factory - mfactory = dns.quic.null_factory + cfactory = dns.quic.null_factory # type: ignore + mfactory = dns.quic.null_factory # type: ignore the_connection = connection else: - (cfactory, mfactory) = dns.quic.factories_for_backend(backend) + (cfactory, mfactory) = dns.quic.factories_for_backend(backend) # type: ignore async with cfactory() as context: async with mfactory( diff --git a/dns/name.py b/dns/name.py index 45c8f454..5af55839 100644 --- a/dns/name.py +++ b/dns/name.py @@ -764,9 +764,9 @@ class Name: l = len(self.labels) if depth == 0: - return (self, dns.name.empty) + return (self, empty) elif depth == l: - return (dns.name.empty, self) + return (empty, self) elif depth < 0 or depth > l: raise ValueError("depth must be >= 0 and <= the length of the name") return (Name(self[:-depth]), Name(self[-depth:])) @@ -1228,8 +1228,8 @@ def _absolute_successor(name: Name, origin: Name, prefix_ok: bool) -> Name: new_labels = [least_significant_label + _MINIMAL_OCTET] new_labels.extend(name.labels[1:]) try: - return dns.name.Name(new_labels) - except dns.name.NameTooLong: + return Name(new_labels) + except NameTooLong: pass # We can't extend the label either, so we'll try to increment the least # signficant non-maximal byte in it. diff --git a/dns/query.py b/dns/query.py index 9baa0ad8..64a2e2d7 100644 --- a/dns/query.py +++ b/dns/query.py @@ -699,11 +699,11 @@ def _http3( q.id = 0 wire = q.to_wire() the_connection: dns.quic.SyncQuicConnection - the_manager: dns.quic.SyncQuicManager + the_manager: dns.quic.SyncQuicManager # type: ignore if connection: manager: contextlib.AbstractContextManager = contextlib.nullcontext(None) else: - manager = dns.quic.SyncQuicManager( + manager = dns.quic.SyncQuicManager( # type: ignore verify_mode=verify, server_name=hostname, h3=True # type: ignore ) the_manager = manager # for type checking happiness @@ -1494,12 +1494,12 @@ def quic( q.id = 0 wire = q.to_wire() the_connection: dns.quic.SyncQuicConnection - the_manager: dns.quic.SyncQuicManager + the_manager: dns.quic.SyncQuicManager # type: ignore if connection: manager: contextlib.AbstractContextManager = contextlib.nullcontext(None) the_connection = connection else: - manager = dns.quic.SyncQuicManager( + manager = dns.quic.SyncQuicManager( # type: ignore verify_mode=verify, server_name=hostname # type: ignore ) the_manager = manager # for type checking happiness diff --git a/dns/zone.py b/dns/zone.py index f68e8e85..b71f244d 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -626,7 +626,7 @@ class Zone(dns.transaction.TransactionManager): f: Any, sorted: bool = True, relativize: bool = True, - nl: str | None = None, + nl: str | bytes | None = None, want_comments: bool = False, want_origin: bool = False, ) -> None: @@ -644,7 +644,7 @@ class Zone(dns.transaction.TransactionManager): names in the output will be relativized to the zone's origin if possible. - *nl*, a ``str`` or None. The end of line string. If not + *nl*, a ``str``, ``bytes``, or None. The end of line string. If not ``None``, the output will use the platform's native end-of-line marker (i.e. LF on POSIX, CRLF on Windows). @@ -662,6 +662,7 @@ class Zone(dns.transaction.TransactionManager): else: cm = contextlib.nullcontext(f) with cm as f: + assert f is not None # must be in this way, f.encoding may contain None, or even # attribute may not be there file_enc = getattr(f, "encoding", None)