-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
[doc] platform module exposes win32_ver function on posix systems #67935
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
Comments
>>> 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 :) |
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. |
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. |
It would break the backward compatibility. Again, it's a delibarate choice. |
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 :) |
I merged #31462, thanks. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: