python / cpython

The Python programming language
https://www.python.org
Other
62.94k stars 30.14k forks source link

documentation on `getsockname()` wrong for AF_INET6 #86786

Open 784abec7-9fe8-4a59-af24-e6697e48e440 opened 3 years ago

784abec7-9fe8-4a59-af24-e6697e48e440 commented 3 years ago
BPO 42620
Nosy @tiran, @miss-islington, @vanrein
PRs
  • python/cpython#23742
  • python/cpython#23906
  • python/cpython#23907
  • 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: ```python assignee = None closed_at = None created_at = labels = ['3.8', 'type-bug', 'library', '3.9', '3.10'] title = 'documentation on `getsockname()` wrong for AF_INET6' updated_at = user = 'https://github.com/vanrein' ``` bugs.python.org fields: ```python activity = actor = 'miss-islington' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'vanrein' dependencies = [] files = [] hgrepos = [] issue_num = 42620 keywords = ['patch'] message_count = 6.0 messages = ['382863', '382868', '382875', '383633', '383634', '383635'] nosy_count = 3.0 nosy_names = ['christian.heimes', 'miss-islington', 'vanrein'] pr_nums = ['23742', '23906', '23907'] priority = 'normal' resolution = None stage = 'patch review' status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue42620' versions = ['Python 3.8', 'Python 3.9', 'Python 3.10'] ```

    784abec7-9fe8-4a59-af24-e6697e48e440 commented 3 years ago

    Shown in the session below is unexpected output of a 4-tuple from an AF_INET6 socket along with documentation that *suggests* to expect a 2-tuple. The phrasing "IP" might have to be toned down to "IPv4" or "AF_INET" to be accurate enough to avoid confusion.

    Opinion: I think you should be explicit about the different behaviour for AF_INET6, so it is not reduced to a special/nut case for special interest groups. IPv6 has a hard enough time getting in; different formats for AF_INET and AF_INET6 should ideally be shown to all programmers, to at least avoid *uninformed* decisions to be incompatible with IPv6 while they develop on an IPv4 system (and the same in the opposite direction).

    Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import socket
    >>> sox6 = socket.socket (socket.AF_INET6)
    >>> sox6.getsockname ()
    ('::', 0, 0, 0)
    >>> sox6.getsockname.__doc__
    'getsockname() -> address info\n\nReturn the address of the local endpoint.  For IP sockets, the address\ninfo is a pair (hostaddr, port).'
    tiran commented 3 years ago

    Good point. The address info depends on the address family, https://docs.python.org/3/library/socket.html#socket-families . I have updated the doc string:

    >>> import socket
    >>> print(socket.socket.getsockname.__doc__)
    getsockname() -> address info

    Return the address of the local endpoint. The format depends on the address family. For IPv4 sockets, the address info is a pair (hostaddr, port).

    784abec7-9fe8-4a59-af24-e6697e48e440 commented 3 years ago

    Excellent, thanks. I personally would appreciate if a remark about IPv6 would also be made.

    miss-islington commented 3 years ago

    New changeset cf3565ca9a7ed0f7decd000e41fa3de400986e4d by Christian Heimes in branch 'master': bpo-42620: Improve socket.getsockname doc string (GH-23742) https://github.com/python/cpython/commit/cf3565ca9a7ed0f7decd000e41fa3de400986e4d

    miss-islington commented 3 years ago

    New changeset b20494618c6ac6ebcd354e0b16a6645fe47acbee by Miss Islington (bot) in branch '3.8': bpo-42620: Improve socket.getsockname doc string (GH-23742) https://github.com/python/cpython/commit/b20494618c6ac6ebcd354e0b16a6645fe47acbee

    miss-islington commented 3 years ago

    New changeset 7fe7d83c26b02c8a65c8a9633cc4251f5cd97ebf by Miss Islington (bot) in branch '3.9': bpo-42620: Improve socket.getsockname doc string (GH-23742) https://github.com/python/cpython/commit/7fe7d83c26b02c8a65c8a9633cc4251f5cd97ebf

    furkanonder commented 1 year ago

    @tiran Issue seems to be resolved. We can close the issue.