Skip to content

bpo-40635: Fix getfqdn() docstring and docs #27971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/library/socket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,9 @@ The :mod:`socket` module also offers various network-related services:
Return a fully qualified domain name for *name*. If *name* is omitted or empty,
it is interpreted as the local host. To find the fully qualified name, the
hostname returned by :func:`gethostbyaddr` is checked, followed by aliases for the
host, if available. The first name which includes a period is selected. In
case no fully qualified domain name is available, the hostname as returned by
:func:`gethostname` is returned.
host, if available. The first name which includes a period is selected. If FQDN is not
available and *name* is empty or is ``'0.0.0.0'``, hostname from :func:`gethostname` is
returned. Otherwise, *name* is returned unchanged.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't exceed 79 characters per line.

Suggested change
host, if available. The first name which includes a period is selected. If FQDN is not
available and *name* is empty or is ``'0.0.0.0'``, hostname from :func:`gethostname` is
returned. Otherwise, *name* is returned unchanged.
host, if available. The first name which includes a period is selected. In
case no fully qualified domain name is available and *name* was provided,
it is returned unchanged. If *name* was empty or equal to ``'0.0.0.0'``,
the hostname as returned by :func:`gethostname` is returned.

Copy link
Contributor Author

@akulakov akulakov Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'as returned ... is returned' reads a bit awkward I think, is it okay if I use the same wording as in your suggestion for the docstring? ; which is:

[...] hostname from gethostname() is returned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, agreed. I just used what was originally in the doc but you're right that the docstring version is an improvement.



.. function:: gethostbyname(hostname)
Expand Down
5 changes: 3 additions & 2 deletions Lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,9 @@ def getfqdn(name=''):
An empty argument is interpreted as meaning the local host.

First the hostname returned by gethostbyaddr() is checked, then
possibly existing aliases. In case no FQDN is available, hostname
from gethostname() is returned.
possibly existing aliases. If that logic fails and `name` is empty or is
'0.0.0.0', hostname from gethostname() is returned. Otherwise, `name` is
returned unchanged.
"""
name = name.strip()
if not name or name == '0.0.0.0':
Expand Down