classification
Title: socket.getsockname() returns string instead of tuple
Type: behavior Stage: resolved
Components: Documentation, Extension Modules Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Brent Gardner, benjamin.peterson, christian.heimes, docs@python
Priority: normal Keywords: patch

Created on 2019-06-25 21:01 by Brent Gardner, last changed 2019-09-12 10:34 by benjamin.peterson. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14392 merged python-dev, 2019-06-26 12:01
PR 16018 merged miss-islington, 2019-09-12 10:03
Messages (5)
msg346559 - (view) Author: Brent Gardner (Brent Gardner) * Date: 2019-06-25 21:01
In Python 3.5.3, a socket with type AF_CAN returns a tuple in the form `(interface, )` from getsockname().  In Python 3.7.3, getsockname() returns a string (the name of the interface).  The documentation states "a tuple is used for the AF_CAN address family".  The string will break code that worked in 3.5.3 by raising errors such as "Value Error: too many values to unpack (expected 2)".

Example:

#3.5.3
import socket
s = socket.socket(socket.AF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
s.bind(('vcan0',)) # requires tuple
s.getsockname() # returns tuple: ('vcan0', 29)

#3.7.3
import socket
s = socket.socket(socket.AF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
s.bind(('vcan0',)) # requires tuple
s.getsockname() # returns string: 'vcan0'
msg346579 - (view) Author: Brent Gardner (Brent Gardner) * Date: 2019-06-26 02:51
Changed caused by commit effc12f8e9e20d0951d2ba5883587666bd8218e3 to cpython/Modules/socketmodule.c on Sep 6, 2017.
msg346580 - (view) Author: Brent Gardner (Brent Gardner) * Date: 2019-06-26 02:54
Correction, change caused by a30f6d45ac3e72761b96a8df0527182029eaee24 to cpython/Modules/socketmodule.c on Aug 28, 2017.
msg352086 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2019-09-12 10:02
New changeset 954900a3f98a8c0dea14dd575490237f3f8626b3 by Benjamin Peterson (bggardner) in branch 'master':
closes bpo-37405: Make socket.getsockname() always return a tuple for AF_CAN. (GH-14392)
https://github.com/python/cpython/commit/954900a3f98a8c0dea14dd575490237f3f8626b3
msg352097 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2019-09-12 10:34
New changeset f60fd95dcc189ace8c0a2177a394b9cc20389a1e by Benjamin Peterson (Miss Islington (bot)) in branch '3.8':
closes bpo-37405: Make socket.getsockname() always return a tuple for AF_CAN. (GH-14392) (GH-16018)
https://github.com/python/cpython/commit/f60fd95dcc189ace8c0a2177a394b9cc20389a1e
History
Date User Action Args
2019-09-12 10:34:31benjamin.petersonsetmessages: + msg352097
2019-09-12 10:03:09miss-islingtonsetpull_requests: + pull_request15641
2019-09-12 10:02:52benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg352086

resolution: fixed
stage: patch review -> resolved
2019-06-26 12:01:59python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request14206
2019-06-26 05:31:55ned.deilysetnosy: + christian.heimes
2019-06-26 02:54:32Brent Gardnersetmessages: + msg346580
2019-06-26 02:51:26Brent Gardnersetmessages: + msg346579
components: + Extension Modules
2019-06-25 21:01:33Brent Gardnersettype: behavior
2019-06-25 21:01:17Brent Gardnercreate