Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions Doc/library/platform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ Cross Platform
for some systems. It also does some reordering of the information in some cases
where it would otherwise cause confusion.

.. versionchanged:: 3.8
On macOS, the function now uses :func:`mac_ver`, if it returns a
non-empty release string, to get the macOS version rather than the darwin
version.


.. function:: version()

Expand Down
9 changes: 8 additions & 1 deletion Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,14 @@ def system_alias(system, release, version):
where it would otherwise cause confusion.

"""
if system == 'SunOS':
if system == 'Darwin':
# macOS (darwin kernel)
macos_release = mac_ver()[0]
if macos_release:
system = 'macOS'
release = macos_release

elif system == 'SunOS':
# Sun's OS
if release < '5':
# These releases use the old name SunOS
Expand Down
23 changes: 17 additions & 6 deletions Lib/test/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,30 +352,41 @@ def test__comparable_version(self):
def test_macos(self):
self.addCleanup(self.clear_caches)

darwin_version = ('Darwin Kernel Version 17.7.0: '
'Thu Jun 21 22:53:14 PDT 2018; '
'root:xnu-4570.71.2~1/RELEASE_X86_64')
uname = ('Darwin', 'hostname', '17.7.0',
('Darwin Kernel Version 17.7.0: '
'Thu Jun 21 22:53:14 PDT 2018; '
'root:xnu-4570.71.2~1/RELEASE_X86_64'),
darwin_version,
'x86_64', 'i386')
uname = platform.uname_result(*uname)
arch = ('64bit', '')
with mock.patch.object(platform, 'uname', return_value=uname), \
mock.patch.object(platform, 'architecture', return_value=arch):
for mac_ver, expected_terse, expected in [
for mac_ver, expected_terse, expected, expected_system_alias in [
# darwin: mac_ver() returns empty strings
(('', '', ''),
'Darwin-17.7.0',
'Darwin-17.7.0-x86_64-i386-64bit'),
'Darwin-17.7.0-x86_64-i386-64bit',
('Darwin', '17.7.0', darwin_version)),
# macOS: mac_ver() returns macOS version
(('10.13.6', ('', '', ''), 'x86_64'),
'macOS-10.13.6',
'macOS-10.13.6-x86_64-i386-64bit'),
'macOS-10.13.6-x86_64-i386-64bit',
('macOS', '10.13.6', darwin_version)),
]:
with mock.patch.object(platform, 'mac_ver',
return_value=mac_ver):
self.clear_caches()
self.assertEqual(platform.platform(terse=1), expected_terse)
self.assertEqual(platform.platform(), expected)

plat_uname = platform.uname()
system_alias = platform.system_alias(plat_uname.system,
plat_uname.release,
plat_uname.version)
self.assertEqual(system_alias,
expected_system_alias)


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
On macOS, :func:`platform.system_alias` now returns macOS and macOS release,
rather than Darwin and Darwin release.