← 输入框|github.com|刷新
Skip to content

socket.getsockname() returns string instead of tuple #81586

Closed

Description

@bggardner
mannequin
BPO 37405
Nosy @tiran, @benjaminp, @bggardner, @fbennett78
PRs
  • bpo-37405: socket.getsockname() returns string instead of tuple #14392
  • [3.8] closes bpo-37405: Make socket.getsockname() always return a tuple for AF_CAN. (GH-14392) #16018
  • bpo-37405: socket.getsockname() test fix #24991
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-09-12.10:02:52.337>
    created_at = <Date 2019-06-25.21:01:17.388>
    labels = ['type-bug', 'tests', '3.10']
    title = 'socket.getsockname() returns string instead of tuple'
    updated_at = <Date 2021-03-23.15:14:42.943>
    user = 'https://github.com/bggardner'

    bugs.python.org fields:

    activity = <Date 2021-03-23.15:14:42.943>
    actor = 'Brent Gardner'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2019-09-12.10:02:52.337>
    closer = 'benjamin.peterson'
    components = ['Tests']
    creation = <Date 2019-06-25.21:01:17.388>
    creator = 'Brent Gardner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37405
    keywords = ['patch']
    message_count = 7.0
    messages = ['346559', '346579', '346580', '352086', '352097', '389364', '389388']
    nosy_count = 5.0
    nosy_names = ['christian.heimes', 'benjamin.peterson', 'docs@python', 'Brent Gardner', 'bennett78']
    pr_nums = ['14392', '16018', '24991']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue37405'
    versions = ['Python 3.10']

    Activity

    1. bggardner commented on Jun 25, 2019

      bggardnermannequin
      MannequinAuthor

      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'
    2. added
      docs
      3.7 (EOL)
      on Jun 25, 2019
    3. added
      type-bug
      on Jun 25, 2019
    4. bggardner commented on Jun 26, 2019

      bggardnermannequin
      MannequinAuthor

      Changed caused by commit effc12f to cpython/Modules/socketmodule.c on Sep 6, 2017.

    5. added
      extension-modules
      on Jun 26, 2019
    6. bggardner commented on Jun 26, 2019

      bggardnermannequin
      MannequinAuthor

      Correction, change caused by a30f6d4 to cpython/Modules/socketmodule.c on Aug 28, 2017.

    7. benjaminp commented on Sep 12, 2019

      @benjaminp
      Contributor

      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

    8. benjaminp commented on Sep 12, 2019

      @benjaminp
      Contributor

      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

    9. fbennett78 commented on Mar 23, 2021

      fbennett78mannequin
      Mannequin
      $ 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+
    10. added
      tests
      3.10 (EOL)
      and removed
      docs
      extension-modules
      3.7 (EOL)
      on Mar 23, 2021
    11. bggardner commented on Mar 23, 2021

      bggardnermannequin
      MannequinAuthor

      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.

    12. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)teststype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions