Skip to content

gh-71199: Always build posixmodule as _os - #161915

Open
cmaloney wants to merge 4 commits into
python:mainfrom
cmaloney:gh-71199-build-as-os
Open

cmaloney wants to merge 4 commits into
python:mainfrom
cmaloney:gh-71199-build-as-os

Conversation

@cmaloney

@cmaloney cmaloney commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

The module was compiled as posix or nt depending on the platform. Build it as _os everywhere with a single PyInit__os. Keep the historical names available for compatibility backed by the same init function so sys.builtin_module_names, find_spec() and loading it by hand (as LazyLoader does) keep working.

Freeze skips posix and nt when writing its config.c, since the inittab templates already map them to PyInit__os.

The module was compiled as posix or nt depending on the platform. Build
it as `_os` everywhere with a single `PyInit__os`. Keep the historical
names available for compatibility backed by the same init function so
sys.builtin_module_names, find_spec() and loading it by hand (as
LazyLoader does).

Freeze skips posix and nt when writing its config.c, since the
inittab templates already map them to PyInit__os.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cmaloney cmaloney closed this Nov 12, 2026
@cmaloney cmaloney reopened this Nov 12, 2026
@read-the-docs-community

read-the-docs-community Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

@cmaloney cmaloney added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 14, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @cmaloney for commit 2922cff 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F161915%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 14, 2026
Comment thread Modules/posixmodule.c
.m_name = MODNAME,
.m_name = "os",
.m_doc = posix__doc__,
.m_size = sizeof(_posixstate),

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.

note: the .m_methods moves to the PyModule_AddFunctions in posixmodule_exec

@cmaloney

Copy link
Copy Markdown
Contributor Author

buildbot failures unrelated to this change.

@StanFromIreland this is ready for you to take a look. This does the module rename from posix or nt to _os always with posix and nt aliases registered when appropriate. All functions now appear as from module os.

Comment thread Doc/library/posix.rst Resolved
Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
@StanFromIreland

Copy link
Copy Markdown
Member

Build it as _os everywhere with a single PyInit__os.

So PyInit_posix/PyInit_nt will disappear meaning embedders with a hand-written inittab that reference those symbols will fail to link, I'm not sure how likely this is to be done.

@StanFromIreland StanFromIreland changed the title gh-71199: Always build posixmodule as _os gh-71199: Always build posixmodule as _os Nov 17, 2026

@StanFromIreland StanFromIreland left a comment

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.

This looks good to me, I suggest waiting a few days before landing this in case others have thoughts.

CC @vstinner you may be interested.

@cmaloney

Copy link
Copy Markdown
Contributor Author

So PyInit_posix/PyInit_nt will disappear meaning embedders with a hand-written inittab that reference those symbols will fail to link, I'm not sure how likely this is to be done.

Fairly straightforward to keep the old names if want to consider those to be part of the API. I was leaning the rename may break some embedding, and eliminating all the unnecessary conditional code is worthwhile to simplify here. Better to have one break (_os always in one step) then two.

If we rename posixmodule.c to _osmodule.c that would make more custom handling possibly break. Currently I'm leaning against that part of the series though (lots of churn for little value)

@vstinner

Copy link
Copy Markdown
Member

"posix" and "nt" names are used/visible in many places. I would prefer to not have a single PR changing everything at once.

This PR changes posixmodule.c module name to os. I don't think that it's a good approach. I would prefer to use _os name instead. What is the reason to lie about the extension name?

We have a similar separation between _socket extension module and socket Python module:

$ python3.15
>>> import posix, os
>>> posix.getpid.__module__
'posix'
>>> os.getpid.__module__
'posix'

>>> import _socket, socket
>>> _socket.gethostname.__module__
'_socket'
>>> socket.gethostname.__module__
'_socket'

@cmaloney

Copy link
Copy Markdown
Contributor Author

Re: _os vs os to not introduce new names as well as reduce future compatibility issues. What is in os.py vs _os C accelerator should, to me, be transparent. If the module moves to exporting things as _os that introduces a new never before used name. I can definitely keep posix and nt module names and make _os show as that if want to minimize change.

My bias here comes from _io where the module name of _io while in theory an internal implementation detail is sufficiently exposed, such as by pickle, that it cannot be changed without breaking things.

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

Labels

awaiting merge type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants