[issue37405] socket.getsockname() returns string instead of tuple
New submission from Brent Gardner <bggardner@gmail.com>: 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' ---------- assignee: docs@python components: Documentation messages: 346559 nosy: Brent Gardner, docs@python priority: normal severity: normal status: open title: socket.getsockname() returns string instead of tuple versions: Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
Change by Brent Gardner <bggardner@gmail.com>: ---------- type: -> behavior _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
Brent Gardner <bggardner@gmail.com> added the comment: Changed caused by commit effc12f8e9e20d0951d2ba5883587666bd8218e3 to cpython/Modules/socketmodule.c on Sep 6, 2017. ---------- components: +Extension Modules _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
Brent Gardner <bggardner@gmail.com> added the comment: Correction, change caused by a30f6d45ac3e72761b96a8df0527182029eaee24 to cpython/Modules/socketmodule.c on Aug 28, 2017. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
Change by Ned Deily <nad@python.org>: ---------- nosy: +christian.heimes _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
Change by Roundup Robot <devnull@psf.upfronthosting.co.za>: ---------- keywords: +patch pull_requests: +14206 stage: -> patch review pull_request: https://github.com/python/cpython/pull/14392 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
Benjamin Peterson <benjamin@python.org> added the comment: 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/954900a3f98a8c0dea14dd575490237f3f8... ---------- nosy: +benjamin.peterson resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +15641 pull_request: https://github.com/python/cpython/pull/16018 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
Benjamin Peterson <benjamin@python.org> added the comment: 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/f60fd95dcc189ace8c0a2177a394b9cc203... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
FRANK BENNETT <fbennett78@reagan.com> added the comment: $ make test TESTOPTS="-v test_socket" ERROR: testSendFrame (__main__.CANTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/s/opt/cpython/debug/test_socket.py", line 2052, in testSendFrame self.assertEqual(addr[1], socket.AF_CAN) IndexError: tuple index out of range $ cat ../.git/config https://github.com/bennett78/cpython.git $ uname -r 5.4.0-67-genericg$ cat /etc/issue Ubuntu 20.04.2 LTS \n \l $ /s/opt/cpython/debug$ ./python -V Python 3.10.0a6+ ---------- components: +Tests -Documentation, Extension Modules nosy: +bennett78 versions: +Python 3.10 -Python 3.7 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
Brent Gardner <bggardner@gmail.com> added the comment: This test was overlooked, and line 2052 should now be removed per the discussion here: https://github.com/python/cpython/pull/14392#issuecomment-506133908 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
Change by Brent Gardner <bggardner@gmail.com>: ---------- pull_requests: +23749 pull_request: https://github.com/python/cpython/pull/24991 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue37405> _______________________________________
participants (6)
-
Benjamin Peterson
-
Brent Gardner
-
FRANK BENNETT
-
miss-islington
-
Ned Deily
-
Roundup Robot