Repository navigation
Description
Bug report
Bug description:
Adding static modules using inittab can include modules in packages (aka dotted-modules), like this:
PyImport_AppendInittab("inittab.staticmod", PyInit_staticmod);and be imported like so in Python code:
import inittab.staticmod
inittab.staticmod.say_hello()This works fine when using a CPython build with assertions disabled, and also works fine with Python 3.12 with assertions enabled.
Since Python 3.13 (and still true on main), importing a dotted-inittab-module in an assertions-enabled build hits a new assertion (added in gh-118204):
Assertion failed: (PyUnicode_FindChar(name, '.', 0, PyUnicode_GetLength(name), -1) == -1), function _Py_ext_module_loader_info_init_for_builtin, file importdl.c, line 178.
It is unclear to me whether it was intentional to make dotted-inittab-modules "not supported", or it was unintended consequence.
The docs don't mention such a limitation when using inittab, and at least as of gh-102700, explicit support for this scenario was added in Python 3.12 and backported to 3.11.
I created a demo repo to demonstrate the issue, with several PRs against it demonstrating that it works with assertions disabled and in 3.12 with assertions enabled.
CPython versions tested on:
3.15, 3.14, CPython main branch, 3.13
Operating systems tested on:
macOS
Linked PRs
- gh-140011: Delete importdl assertion that prevents importing embedded modules from packages #141605
- [3.14] gh-140011: Delete importdl assertion that prevents importing embedded modules from packages (GH-141605) #141986
- [3.13] gh-140011: Delete importdl assertion that prevents importing embedded modules from packages (GH-141605) #141987
Activity
itamaro commentedon Oct 12, 2025
cc @ericsnowcurrently as the author of gh-118204
Workaround assertion with Native Python extensions in packages
Merge branch 'main' into pythongh-140011-dotted-import
gh-140011: Delete importdl assertion that prevents importing embedded…
pythongh-140011: Delete importdl assertion that prevents importing em…
pythongh-140011: Delete importdl assertion that prevents importing em…
[3.14] gh-140011: Delete importdl assertion that prevents importing e…
[3.13] gh-140011: Delete importdl assertion that prevents importing e…
pythongh-140011: Delete importdl assertion that prevents importing em…
pythongh-140011: Delete importdl assertion that prevents importing em…