Skip to content

bpo-37405: socket.getsockname() returns string instead of tuple #14392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 12, 2019
4 changes: 3 additions & 1 deletion Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,9 @@ def testCreateBCMSocket(self):

def testBindAny(self):
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
s.bind(('', ))
address = ('', )
s.bind(address)
self.assertEqual(s.getsockname(), address)

def testTooLongInterfaceName(self):
# most systems limit IFNAMSIZ to 16, take 1024 to be sure
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed regression bug for socket.getsockname() for non-CAN_ISOTP AF_CAN
address family sockets by returning a 1-tuple instead of string.
2 changes: 1 addition & 1 deletion Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
#endif /* CAN_ISOTP */
default:
{
return Py_BuildValue("O&", PyUnicode_DecodeFSDefault,
return Py_BuildValue("(O&)", PyUnicode_DecodeFSDefault,
ifname);
}
}
Expand Down