classification
Title: socket.getaddrinfo() should support keyword arguments
Type: Stage:
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: exarkun, giampaolo.rodola, pitrou
Priority: normal Keywords: patch

Created on 2010-05-31 22:50 by giampaolo.rodola, last changed 2010-08-17 15:31 by giampaolo.rodola. This issue is now closed.

Files
File name Uploaded Description Edit
getaddrinfo.patch giampaolo.rodola, 2010-08-14 18:04
Messages (8)
msg106817 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-05-31 22:50
As of now socket.getaddrinfo() only supports positional arguments, so that if I want to, say, specify "flags" argument I'm forced to specify "0" for other missing arguments:

>>> socket.getaddrinfo("www.python.org", 0, 0, 0, socket.SOL_TCP)
[(2, 1, 6, '', ('82.94.164.162', 0)), (10, 1, 6, '', ('2001:888:2000:d::a2', 0, 0, 0))]
>>>
>>> socket.getaddrinfo("www.python.org", flags=socket.SOL_TCP)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: getaddrinfo() takes no keyword arguments
>>>
msg106818 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-05-31 22:52
...also, the returning tuples could be named tuples instead.
msg106909 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-06-02 20:08
The patch in attachment implements keyword arguments.
msg106917 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-06-02 21:33
Created issue 8881 to treat the named tuples issue separately.
msg113919 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-08-14 18:04
Updated patch in attachment includes tests and doc update.

I decided to rename "socktype" argument in "type", since that's the name adopted all across the socket module API:

socket.socket([family[, type[, proto]]])
socket.socket.type
socket.socketpair([family[, type[, proto]]])
socket.fromfd(fd, family, type[, proto])

This is safe and doesn't introduce any incompatibility.
msg113933 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-14 21:57
-.. function:: getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0)
+.. function:: getaddrinfo(host, port[, family[, type[, proto[, flags]]]])

You should keep using the new documentation convention, that is:

.. function:: getaddrinfo(host, port, family=0, type=0, proto=0, flags=0)
msg114125 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-08-17 14:55
Isn't that exactly as it was before?
Being now possible to specify single keyword arguments aren't "[" brackets necessary?
msg114129 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-08-17 15:31
Committed in r84143 including the doc change as suggested by Antoine.
History
Date User Action Args
2010-08-17 15:31:26giampaolo.rodolasetstatus: open -> closed
resolution: fixed
messages: + msg114129
2010-08-17 14:55:12giampaolo.rodolasetmessages: + msg114125
2010-08-14 21:57:43pitrousetmessages: + msg113933
2010-08-14 18:05:14giampaolo.rodolasetfiles: - kwargs.patch
2010-08-14 18:04:54giampaolo.rodolasetfiles: + getaddrinfo.patch

messages: + msg113919
2010-06-02 21:33:13giampaolo.rodolasetmessages: + msg106917
2010-06-02 20:08:17giampaolo.rodolasetfiles: + kwargs.patch
keywords: + patch
messages: + msg106909
2010-05-31 22:52:18giampaolo.rodolasetmessages: + msg106818
2010-05-31 22:50:11giampaolo.rodolacreate