From 23529c005d9566bf5e9592fa0742555f9310f68e Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Tue, 30 Jun 2026 16:37:42 +0200 Subject: [PATCH] gh-152433: Windows: ``_winapi.c`` implement ``GetVersion()`` UWP alternative --- .../2026-06-30-16-40-00.gh-issue-152433.VaeEwR.rst | 1 + Modules/_winapi.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 Misc/NEWS.d/next/Windows/2026-06-30-16-40-00.gh-issue-152433.VaeEwR.rst diff --git a/Misc/NEWS.d/next/Windows/2026-06-30-16-40-00.gh-issue-152433.VaeEwR.rst b/Misc/NEWS.d/next/Windows/2026-06-30-16-40-00.gh-issue-152433.VaeEwR.rst new file mode 100644 index 000000000000000..00f89ffcbc1c29a --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2026-06-30-16-40-00.gh-issue-152433.VaeEwR.rst @@ -0,0 +1 @@ +``_winapi``: implement ``GetVersion()`` UWP alternative. diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 535784adedb24d8..a649d84a7925a04 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -1739,7 +1739,19 @@ _winapi_GetVersion_impl(PyObject *module) #pragma warning(disable:4996) { +#ifdef MS_WINDOWS_DESKTOP return GetVersion(); +#else + OSVERSIONINFOW version_info; + ZeroMemory(&version_info, sizeof(version_info)); + version_info.dwOSVersionInfoSize = sizeof(version_info); + if (GetVersionExW(&version_info)) { + return version_info.dwMinorVersion | + (version_info.dwMajorVersion << 8) | + (version_info.dwBuildNumber << 16); + } + return 0; +#endif } #pragma warning(pop)