You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
socket.getsockname() returns string instead of tuple #81586
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)".
New changeset 954900a by Benjamin Peterson (bggardner) in branch 'master':
closes bpo-37405: Make socket.getsockname() always return a tuple for AF_CAN. (GH-14392) 954900a
New changeset f60fd95 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) f60fd95
Traceback (most recent call last):
File "/s/opt/cpython/debug/test_socket.py", line 2052, in testSendFrameself.assertEqual(addr[1], socket.AF_CAN)
IndexError: tuple index out of range
In short, getsockname() used to return (interface, socket.AF_CAN), in which the socket.AF_CAN element was superfluous (also undocumented), so it was removed in the fix, and the tuple format was reinstated.
Activity
bggardner commentedon Jun 25, 2019
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:
bggardner commentedon Jun 26, 2019
Changed caused by commit effc12f to cpython/Modules/socketmodule.c on Sep 6, 2017.
bggardner commentedon Jun 26, 2019
Correction, change caused by a30f6d4 to cpython/Modules/socketmodule.c on Aug 28, 2017.
benjaminp commentedon Sep 12, 2019
New changeset 954900a by Benjamin Peterson (bggardner) in branch 'master':
closes bpo-37405: Make socket.getsockname() always return a tuple for AF_CAN. (GH-14392)
954900a
benjaminp commentedon Sep 12, 2019
New changeset f60fd95 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)
f60fd95
fbennett78 commentedon Mar 23, 2021
ERROR: testSendFrame (main.CANTest)
----------------------------------------------------------------------
bggardner commentedon Mar 23, 2021
This test was overlooked, and line 2052 should now be removed per the discussion here:
#14392 (comment)
In short, getsockname() used to return
(interface, socket.AF_CAN), in which the socket.AF_CAN element was superfluous (also undocumented), so it was removed in the fix, and the tuple format was reinstated.