Skip to content

gh-152433: Windows: improve sys.getwindowsversion(), use RtlGetVersion() and allow build for UWP#152604

Open
thexai wants to merge 1 commit into
python:mainfrom
thexai:windows-version
Open

gh-152433: Windows: improve sys.getwindowsversion(), use RtlGetVersion() and allow build for UWP#152604
thexai wants to merge 1 commit into
python:mainfrom
thexai:windows-version

Conversation

@thexai

@thexai thexai commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@thexai

thexai commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

For more context, the actual issue with sys.getwindowsversion() is that return incorrect value in recent Windows 11 versions:

e.g: in Windows 11 25H2 return 10.0.26100 instead of correct 10.0.26200.

(but not directly observable because only is used as second fallback on platform module)

With this change, it will be possible use sys.getwindowsversion() as the first fallback (after WMI) and will also be compatible with UWP.

In UWP, it would be the primary method because WMI is not available and subprocess "cmd ver" is also not available.

Related to #129294

@thexai
thexai force-pushed the windows-version branch from 3e025ce to e641600 Compare July 23, 2026 09:19
@thexai thexai changed the title gh-152433: Windows: improve sys.getwindowsversion() use RtlGetVersion for Desktop gh-152433: Windows: improve sys.getwindowsversion(), use RtlGetVersion() and allow build for UWP Jul 23, 2026
@thexai
thexai force-pushed the windows-version branch from e641600 to 79ebd57 Compare July 23, 2026 09:25
@thexai
thexai force-pushed the windows-version branch from 79ebd57 to a23a7a4 Compare July 23, 2026 13:48
Comment thread Python/sysmodule.c

Py_BEGIN_ALLOW_THREADS
hKernel32 = GetModuleHandleW(L"kernel32.dll");
hMod = GetModuleHandleW(L"ntdll.dll");

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.

No thanks, we don't use ntdll from CPython.

We should be changing this function to return the version number controlled by the compatibility shims, because it will match the other compatibility behaviours that are associated with that version.

The platform module exists to get the "real" version.

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.

I think we went down the "read kernel32" path because this function used to be used by platform, but that module should be fully relying on WMI now, which is more accurate (if slower, but checking the version number shouldn't be a common task, and certainly not one that's used in tight loops).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows version from sys.getwindowsversion() is wrong in binaries that do not declare Windows 10 support

2 participants