Skip to content

Commit ce0d374

Browse files
committed
Add a new field device_family in version and not call _syscmd_ver() in UWP
1 parent 5dab92e commit ce0d374

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

Lib/platform.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,16 @@ def _win32_ver(version, csd, ptype):
427427

428428
winver = getwindowsversion()
429429
is_client = (getattr(winver, 'product_type', 1) == 1)
430-
try:
431-
version = _syscmd_ver()[2]
432-
major, minor, build = map(int, version.split('.'))
433-
except ValueError:
434-
major, minor, build = winver.platform_version or winver[:3]
430+
431+
if winver.device_family == "Desktop":
432+
try:
433+
version = _syscmd_ver()[2]
434+
major, minor, build = map(int, version.split('.'))
435+
except ValueError:
436+
major, minor, build = winver.platform_version or winver[:3]
437+
version = '{0}.{1}.{2}'.format(major, minor, build)
438+
else:
439+
major, minor, build = winver[:3]
435440
version = '{0}.{1}.{2}'.format(major, minor, build)
436441

437442
# getwindowsversion() reflect the compatibility mode Python is

Python/sysmodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,7 @@ static PyStructSequence_Field windows_version_fields[] = {
16331633
{"suite_mask", "Bit mask identifying available product suites"},
16341634
{"product_type", "System product type"},
16351635
{"platform_version", "Diagnostic version number"},
1636+
{"device_family", "Desktop or UWP"},
16361637
{0}
16371638
};
16381639

@@ -1775,6 +1776,10 @@ sys_getwindowsversion_impl(PyObject *module)
17751776
}
17761777

17771778
SET_VERSION_INFO(realVersion);
1779+
SET_VERSION_INFO(PyUnicode_FromString("Desktop"));
1780+
#else
1781+
SET_VERSION_INFO(Py_BuildValue("(kkk)", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber));
1782+
SET_VERSION_INFO(PyUnicode_FromString("UWP"));
17781783
#endif
17791784

17801785
#undef SET_VERSION_INFO

0 commit comments

Comments
 (0)