From: Bob Halley Date: Wed, 8 Oct 2025 18:21:54 +0000 (-0700) Subject: Rename the getaddrinfo parameter "socktype" to "type" [#1231] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1145a342bd9bd833e4c76f9ad3fadf37416ce3b7;p=thirdparty%2Fdnspython.git Rename the getaddrinfo parameter "socktype" to "type" [#1231] The socket type parameter to socket.getaddrinfo used to be called "socktype" in Python 2, but was renamed to "type" in Python 3. We applied this change on the python3 branch almost a decade ago, but it was lost in the "single code base, only Python 3" update, also quite some time ago. It is now renamed to "type" (again) so it matches the Python 3 code it is overriding. --- diff --git a/dns/resolver.py b/dns/resolver.py index 0c0790e5..3ca2da51 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -1839,7 +1839,7 @@ _original_gethostbyaddr = socket.gethostbyaddr def _getaddrinfo( - host=None, service=None, family=socket.AF_UNSPEC, socktype=0, proto=0, flags=0 + host=None, service=None, family=socket.AF_UNSPEC, type=0, proto=0, flags=0 ): if flags & socket.AI_NUMERICHOST != 0: # Short circuit directly into the system's getaddrinfo(). We're @@ -1847,7 +1847,7 @@ def _getaddrinfo( # because dns.query.* needs to call getaddrinfo() for IPv6 scoping # reasons. We will also do this short circuit below if we # discover that the host is an address literal. - return _original_getaddrinfo(host, service, family, socktype, proto, flags) + return _original_getaddrinfo(host, service, family, type, proto, flags) if flags & (socket.AI_ADDRCONFIG | socket.AI_V4MAPPED) != 0: # Not implemented. We raise a gaierror as opposed to a # NotImplementedError as it helps callers handle errors more @@ -1867,13 +1867,13 @@ def _getaddrinfo( # Is host None or an address literal? If so, use the system's # getaddrinfo(). if host is None: - return _original_getaddrinfo(host, service, family, socktype, proto, flags) + return _original_getaddrinfo(host, service, family, type, proto, flags) try: # We don't care about the result of af_for_address(), we're just # calling it so it raises an exception if host is not an IPv4 or # IPv6 address. dns.inet.af_for_address(host) - return _original_getaddrinfo(host, service, family, socktype, proto, flags) + return _original_getaddrinfo(host, service, family, type, proto, flags) except Exception: pass # Something needs resolution! @@ -1905,20 +1905,20 @@ def _getaddrinfo( if port is None: raise socket.gaierror(socket.EAI_NONAME, "Name or service not known") tuples = [] - if socktype == 0: + if type == 0: socktypes = [socket.SOCK_DGRAM, socket.SOCK_STREAM] else: - socktypes = [socktype] + socktypes = [type] if flags & socket.AI_CANONNAME != 0: cname = canonical_name else: cname = "" for addr, af in addrs: - for socktype in socktypes: - for sockproto in _protocols_for_socktype[socktype]: + for type in socktypes: + for sockproto in _protocols_for_socktype[type]: proto = int(sockproto) addr_tuple = dns.inet.low_level_address_tuple((addr, port), af) - tuples.append((af, socktype, proto, cname, addr_tuple)) + tuples.append((af, type, proto, cname, addr_tuple)) if len(tuples) == 0: raise socket.gaierror(socket.EAI_NONAME, "Name or service not known") return tuples diff --git a/doc/whatsnew.rst b/doc/whatsnew.rst index 7fd48591..73bc2b29 100644 --- a/doc/whatsnew.rst +++ b/doc/whatsnew.rst @@ -8,6 +8,12 @@ What's New in dnspython TBD +* The socket type parameter to socket.getaddrinfo used to be called "socktype" in + Python 2, but was renamed to "type" in Python 3. We applied this change on + the python3 branch almost a decade ago, but it was lost in the "single code base, + only Python 3" update, also quite some time ago. It is now renamed to "type" + (again) so it matches the Python 3 code it is overriding. + 2.8.0 ----- diff --git a/tests/test_resolver_override.py b/tests/test_resolver_override.py index be9e53f2..b1ce54c2 100644 --- a/tests/test_resolver_override.py +++ b/tests/test_resolver_override.py @@ -155,7 +155,7 @@ class OverrideSystemResolverTestCase(unittest.TestCase): infos = socket.getaddrinfo( service=53, family=socket.AF_INET, - socktype=socket.SOCK_DGRAM, + type=socket.SOCK_DGRAM, proto=socket.IPPROTO_UDP, ) self.assertEqual(len(infos), 1)