Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add a new field device_family in version and not call ``_syscmd_v…
…er()`` in UWP
  • Loading branch information
thexai committed Jul 25, 2026
commit ce0d374dff27e1d3cbaba472688dfe8d2972e66b
15 changes: 10 additions & 5 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,16 @@ def _win32_ver(version, csd, ptype):

winver = getwindowsversion()
is_client = (getattr(winver, 'product_type', 1) == 1)
try:
version = _syscmd_ver()[2]
major, minor, build = map(int, version.split('.'))
except ValueError:
major, minor, build = winver.platform_version or winver[:3]

if winver.device_family == "Desktop":
try:
version = _syscmd_ver()[2]
major, minor, build = map(int, version.split('.'))
except ValueError:
major, minor, build = winver.platform_version or winver[:3]
version = '{0}.{1}.{2}'.format(major, minor, build)
else:
major, minor, build = winver[:3]
version = '{0}.{1}.{2}'.format(major, minor, build)

# getwindowsversion() reflect the compatibility mode Python is
Expand Down
5 changes: 5 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,7 @@ static PyStructSequence_Field windows_version_fields[] = {
{"suite_mask", "Bit mask identifying available product suites"},
{"product_type", "System product type"},
{"platform_version", "Diagnostic version number"},
{"device_family", "Desktop or UWP"},
{0}
};

Expand Down Expand Up @@ -1775,6 +1776,10 @@ sys_getwindowsversion_impl(PyObject *module)
}

SET_VERSION_INFO(realVersion);
SET_VERSION_INFO(PyUnicode_FromString("Desktop"));
#else
SET_VERSION_INFO(Py_BuildValue("(kkk)", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber));
SET_VERSION_INFO(PyUnicode_FromString("UWP"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to do this (which I like, tbqh), then we should handle all the API partitions that we have checks for, rather than assuming that anything "not DESKTOP" is UWP.

I believe the UWP case is covered by MS_WINDOWS_APP, and then we should also handle MS_WINDOWS_SYSTEM and MS_WINDOWS_GAMES.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MS_WINDOWS_SYSTEM is only for build system drivers/services and it doesn't seem relevant to Python or applications that has Python embedded. I don't think it needs to be defined, and I believe the instances where it appears should be removed from the code.

MS_WINDOWS_GAMES is only for Xbox Games and it's another flavor of UWP.

MS_WINDOWS_APP is for Xbox Apps and formerly also for "Windows Phone" (which no longer exists). It has the peculiarity (or complication) that it's also defined when compiling for Desktop (because Universal Apps can run also on Desktop).

Then maybe define names "Desktop" "UWP-Games" and "UWP-Apps" or even better:

"Desktop" "Xbox" "UWP" (because MS_WINDOWS_APP is still "universal").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you've changed here looks fine to me. It wouldn't surprise me if one day we regret using "Xbox" instead of "Games", but that day is likely to be a long way out, and it won't be any worse than places where we used "darwin" instead of "macos".

#endif

#undef SET_VERSION_INFO
Expand Down
Loading