Visitar URL original
gh-60856: Be explicit about localhost for socket.getfqdn by slateny · Pull Request #93451 · python/cpython · GitHub
Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move description from last sentence to top
  • Loading branch information
slateny committed Mar 3, 2024
commit dd58cfecae8d09e9996720d8339d1263324359f4
7 changes: 3 additions & 4 deletions Doc/library/socket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -965,14 +965,13 @@ The :mod:`socket` module also offers various network-related services:

.. function:: getfqdn([name])

Return a fully qualified domain name for *name*. If *name* is omitted or empty,
it is interpreted as the local host (as returned by :func:`gethostname`).
Return a fully qualified domain name for *name*. If *name* is empty or equal to
``'0.0.0.0'``, the hostname from :func:`gethostname` is returned.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it so? Looking at the sources, it tries to return one of names returned by gethostbyaddr(gethostname()).

The new wording also leaves unclear what getfqdn() returns.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The source/behavior was changed in #100375 after this PR was opened, so wording definitely does need updating.

Regarding the unclear new wording, could you expand on that? My interpretation is that previously the entire paragraph needs to be read through before the return of getfqdn(), but now it's right at the top: If *name* is empty ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now it starts from the rare corner case (why would anyone pass an empty name to getfqdn()?), but the documentation for getfqdn() without arguments is removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are very correct, leaving out the empty argument is my mistake. What do you think about this instead?

Return a fully qualified domain name for *name*.
To find the fully qualified name, ...
...
... it is returned unchanged.
If *name* is empty, or equal to "0.0.0.0," "::", or "",
the hostname from :func:`gethostname` is returned.

There's also an option of changing getfqdn([name]) to getfqdn(name=''), but not sure if it helps with improving the wording much.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that both changing the wording and changing the signature are worth to do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, let me know if there's anything that looks off. For reference, here's the preview of getfqdn.

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 and *name* was provided,
it is returned unchanged. If *name* was empty or equal to ``'0.0.0.0'``,
the hostname from :func:`gethostname` is returned.
it is returned unchanged.


.. function:: gethostbyname(hostname)
Expand Down