Title: misleading comment in socket.gethostname() documentation
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Rosuav, berker.peksag, docs@python, georg.brandl, ned.deily, orsenthil, python-dev
Priority: normal Keywords: patch

Created on 2009-03-31 16:02 by ned.deily, last changed 2016-01-20 06:46 by berker.peksag. This issue is now closed.

File name Uploaded Description Edit
issue5626_v1.diff berker.peksag, 2012-03-01 16:44 Remove misleading comment. review
Messages (6)
msg84816 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2009-03-31 16:02
The documentation for socket.gethostname() contains the following 

"If you want to know the current machine’s IP address, you may want to 
use gethostbyname(gethostname()). This operation assumes that there is a 
valid address-to-host mapping for the host, and the assumption does not 
always hold."

This comment leads to the mistaken assumption that a machine has only 
one IP address, an assumption which results in bugs such as in 
Issue5625.  The comment also does not deal with other address families, 
i.e. IPv6 addresses.  Either the paragraph should be expanded to cover 
multiple addresses and families, requiring the use of other socket 
functions, or the paragraph should simply be removed.
msg212554 - (view) Author: Chris Angelico (Rosuav) * Date: 2014-03-02 14:39
Python doesn't currently have any sort of function for fetching all a computer's IPs, as far as I know, but if there is one (either now or in the future), it would be good to link to that from there. "Here's how to get your host name. And if you're interested, over there is how to get your IP addresses." Otherwise, removing the potentially-misleading information (this is going to return something in for a lot of systems) seems the reasonable option.
msg258565 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-01-19 01:16
Given that we have not received any more reports on users tripping up on this message, it seems to me that we could just ignore this report and close it. Thoughts?
msg258567 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-01-19 01:52
The point still stands that speaking of "the current machine's IP address" is misleading at best.  I'd say either apply Berker's suggested patch or expand the description to better reflect the real world of multiple interfaces.  Of course I'm biased.
msg258601 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-01-19 15:23
I agree with Chris and Ned. I will apply issue5626_v1.diff today.
msg258649 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-01-20 06:46
New changeset e1a711808cfe by Berker Peksag in branch '3.5':
Issue #5626: Remove misleading comment from socket.gethostname() documentation

New changeset 689f881dd5d1 by Berker Peksag in branch 'default':
Issue #5626: Remove misleading comment from socket.gethostname() documentation
Date User Action Args
2016-01-20 06:46:38berker.peksagsetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2016-01-20 06:46:01python-devsetnosy: + python-dev
messages: + msg258649
2016-01-19 15:23:02berker.peksagsettype: behavior
stage: commit review
messages: + msg258601
versions: + Python 3.5, Python 3.6, - Python 2.6, Python 3.0, Python 3.1
2016-01-19 01:52:09ned.deilysetmessages: + msg258567
2016-01-19 01:16:42orsenthilsetnosy: + orsenthil
messages: + msg258565
2014-03-02 14:39:26Rosuavsetnosy: + Rosuav
messages: + msg212554
2012-03-01 16:44:33berker.peksagsetnosy: + berker.peksag
2012-03-01 16:44:15berker.peksagsetfiles: + issue5626_v1.diff
keywords: + patch
2010-07-31 15:48:13BreamoreBoysetassignee: georg.brandl -> docs@python

nosy: + docs@python
2009-03-31 16:02:52ned.deilycreate