GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-152433: Windows: change ``winreg`` to conditional import for UWP compatibility by thexai · Pull Request #154918 · python/cpython

Conversation

@thexai

@thexai thexai commented Jul 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

In current code, winreg module is not build because code guards not include MS_WINDOWS_APP:

Instead of add MS_WINDOWS_APP condition, guards removed when is:

#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)

(as includes all Windows families)

Or replaced with MS_WINDOWS when code is for all platforms.

The clinic's code also regenerated, resulting in the removal of many redundant conditions.

Note that Windows Registry is not accessible from UWP Apps (or Games) but for consistency is necessary build module as is imported in many places at Python initialization. The same logic was already being applied with MS_WINDOWS_GAMES build.

Windows Registry is not accessible from UWP Apps (or Games), since module is not build, changed the import to conditional to able initialize Python in UWP without winreg module.

  • Issue: Windows: improve compatibility to build for UWP / Xbox #152433

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thexai
thexai requested a review from a team as a code owner July 30, 2026 11:24
@bedevere-app bedevere-app Bot mentioned this pull request Jul 30, 2026
Windows: improve compatibility to build for UWP / Xbox #152433
Open
@bedevere-app bedevere-app Bot added the awaiting review label Jul 30, 2026
@zooba

zooba commented Jul 30, 2026

Copy link
Copy Markdown
Member

Out of interest, what would it look like to make those imports conditional? They ought to be anyway, and I suspect we'll end up with better overall behaviour if they handle this as "no registry access exists" rather than "registry accesses always fail".

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thexai

thexai commented Jul 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I don't really know how it would be done because it requires modifying a lot of Python code and introduce helper functions or constants to identify UWP / GAMES builds as "another platform". This is beyond the scope of this PR.

In addition to this, I want to avoid modifying the behavior of MS_WINDOWS_GAMES builds because I have no easy way to test it (nor any particular interest).

This PR allows compile the current code for UWP and is actually a simplification because it removes 185 lines of code. Without this PR, the resulting UWP builds won't work because they try to import a module that doesn't exist --> hard crash.

With this PR, you can use the rest of the Python code in UWP, and even if a Python script includes import winreg lines and the the script handles the exceptions, return values, etc. nothing bad happens.

Previously, Windows Registry was available for "Windows Phone" in the MS_WINDOWS_APP partition, and most of the Win32 Registry API is still defined. This is why compile winreg.c code for MS_WINDOWS_APP/GAMES is possible and doesn't produce errors. I'm not actually sure if accessing the Registry outside of classic Desktop environment is still useful on other types of devices (Surface or ARM64 devices).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented Jul 30, 2026

Copy link
Copy Markdown
Member

Having had a quick look, it seems like Lib\importlib\_bootstrap_external.py is the only one that needs handling. getpath.py and the rest of the standard library uses are protected (apart from one in IDLE, which I assume you don't care about).

Some of the test suite also assumes the module will be there, and those ought to be handled either at the winreg import or the command importing the module that requires it.

There's no need to modify anything conditionally on the build, it's just going to be something like:

try:
    import winreg
except ImportError:
    winreg = None

...

if winreg:
    # do the thing requiring the registry
else:
    # fallback behaviour if needed

For _bootstrap_external.py I think it's just an entire block that's already optional for non-Windows, so that can become for non-winreg, and it should be good.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thexai

thexai commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Having had a quick look, it seems like Lib\importlib_bootstrap_external.py is the only one that needs handling.

try:
    import winreg
except ImportError:
    winreg = None

Tested this change on UWP build and works fine and seems is enough. I'm going to update the PR with this.

chris-eibl reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thexai
pythongh-152433: Windows: change winreg to conditional import for…
e600361
… UWP compatibility
@thexai
thexai force-pushed the uwp-winreg branch from f2fdab2 to e600361 Compare July 31, 2026 16:43
@thexai
thexai requested review from FFY00, brettcannon, ericsnowcurrently, ncoghlan and warsaw as code owners July 31, 2026 16:43
@thexai thexai changed the title gh-152433: Windows: Allow build winreg module for UWP gh-152433: Windows: change winreg to conditional import for UWP compatibility Jul 31, 2026
chris-eibl
chris-eibl approved these changes Sep 5, 2026
View reviewed changes

@chris-eibl chris-eibl left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@zooba's suggestion works, so approving.

This is sitting for a while now. If nobody objects, I'm gonna merge end of next week at the latest.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thexai reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Sep 5, 2026
@brettcannon
brettcannon removed their request for review September 10, 2026 19:15
@chris-eibl
chris-eibl merged commit fff3c4f into python:main Sep 11, 2026
54 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Sep 11, 2026
@thexai
thexai deleted the uwp-winreg branch September 11, 2026 15:01
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
@thexai @clin1234
pythongh-152433: Windows: change winreg to conditional import for…
4c12b5f
… UWP compatibility (python#154918)
johnslavik pushed a commit to johnslavik/cpython that referenced this pull request Sep 14, 2026
@thexai @johnslavik
pythongh-152433: Windows: change winreg to conditional import for…
1394465
… UWP compatibility (python#154918)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chris-eibl chris-eibl chris-eibl approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@thexai @zooba @chris-eibl
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.