This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [doc] platform module exposes win32_ver function on posix systems
Type: Stage: patch review
Components: Documentation, Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, pythonhacker, r.david.murray, slateny, vstinner
Priority: normal Keywords: easy, patch

Created on 2015-03-23 09:30 by pythonhacker, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 31462 open slateny, 2022-02-21 08:30
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
2022-04-11 14:58:14adminsetgithub: 67935
2022-02-21 08:30:09slatenysetkeywords: + patch
nosy: + slateny

pull_requests: + pull_request29591
stage: needs patch -> patch review
2021-12-13 17:40:54iritkatrielsetkeywords: + easy
title: platform module exposes win32_ver function on posix systems -> [doc] platform module exposes win32_ver function on posix systems
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.4, Python 3.5
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