]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Rename the getaddrinfo parameter "socktype" to "type" [#1231]
authorBob Halley <halley@dnspython.org>
Wed, 8 Oct 2025 18:21:54 +0000 (11:21 -0700)
committerBob Halley <halley@dnspython.org>
Wed, 8 Oct 2025 18:21:54 +0000 (11:21 -0700)
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.

dns/resolver.py
doc/whatsnew.rst
tests/test_resolver_override.py

index 0c0790e5c175ebd500f0ab4434916244e7f40dd1..3ca2da51e38fd97644cd8c9adb2db0c310d0c55c 100644 (file)
@@ -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
index 7fd4859197524b2a7cb5dfbfd5659ee21499179f..73bc2b29f382164a40b3776890c61f7dda081984 100644 (file)
@@ -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
 -----
 
index be9e53f27aa7424bb4b6504f9853f2befe46a3f2..b1ce54c272956e8cb68f04d20d1459ecad6ab14b 100644 (file)
@@ -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)