classification
Title: platform module exposes win32_ver function on posix systems
Type: Stage: needs patch
Components: Documentation, Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, pythonhacker, r.david.murray, vstinner
Priority: normal Keywords:

Created on 2015-03-23 09:30 by pythonhacker, last changed 2015-03-24 14:26 by r.david.murray.

Messages (5)
msg238995 - (view) Author: Anand B Pillai (pythonhacker) * Date: 2015-03-23 09:30
>>> import platform
>>> platform.system()
'Linux'
>>> platform.win32_ver()
('', '', '', '')

Why is this function even exposed on Linux ? It should be conditionally exposed only on win32 platforms. 

Funny that this is coming from the module named "platform" itself :)
msg238996 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-03-23 09:33
> Why is this function even exposed on Linux?

It is a deliberate design choice of the platform module. mac_ver(), win32_ver() and linux_distribution() are available on all platforms.

mac_ver() says "entries which cannot be determined are set to ''. All tuple entries are strings."

Maybe it should be better explained in the doc.
msg238997 - (view) Author: Anand B Pillai (pythonhacker) * Date: 2015-03-23 09:36
Similarly for mac_ver, java_ver etc.

>>> platform.mac_ver()
('', ('', '', ''), '')
>>> platform.java_ver()
('', '', ('', '', ''), ('', '', ''))

Maybe it is okay if these functions are present, but can't they raise an exception or return None instead of returning these funny tuples when empty strings ?

I am surprised at Python's inconsistency in such things. For example,

>>> import winsound
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'winsound'

Works as expected on Linux. In the same vein, these functions shouldn't be present as well IMHO - I agree this is debatable of course.
msg239001 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-03-23 09:50
> Maybe it is okay if these functions are present, but can't they raise an exception or return None instead of returning these funny tuples when empty strings ?

It would break the backward compatibility. Again, it's a delibarate choice.
msg239126 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-03-24 14:26
It is a deliberate choice because the functions accept default values to be returned if the actual values cannot be determined, and because it is easier therefore to write cross-platform scripts if the functions do *not* raise an error when called on the "wrong" platform.  There are other functions in the platform module to use to determine which platform you are on.

Agreed that the fact that they work is currently documented only by implication for those familiar with our doc style (that is, there are no "avaiability" tags, implying they are available on all platforms).  This should be corrected, probably in an introductory paragraph (which will be overlooked by most people reading the docs :)
History
Date User Action Args
2015-03-24 14:26:34r.david.murraysetmessages: - msg239124
2015-03-24 14:26:24r.david.murraysetmessages: + msg239126
stage: needs patch
2015-03-24 14:18:06r.david.murraysetnosy: + r.david.murray
messages: + msg239124
2015-03-23 09:50:54vstinnersetmessages: + msg239001
2015-03-23 09:36:00pythonhackersetmessages: + msg238997
2015-03-23 09:33:45vstinnersetversions: + Python 2.7, Python 3.4, Python 3.5
nosy: + docs@python, vstinner

messages: + msg238996

assignee: docs@python
components: + Documentation
2015-03-23 09:30:16pythonhackercreate