Skip to content

[3.15] gh-157384: Set package context in PyImport_CreateModuleFromInitfunc() (GH-157387) - #159316

Merged
encukou merged 1 commit into
python:3.15from
miss-islington:backport-0486228-3.15
Oct 14, 2026
Merged

encukou merged 1 commit into
python:3.15from
miss-islington:backport-0486228-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

A single-phase init function that creates its module using only the
last component of a dotted name (as pybind11 does for submodules) got
a module whose name was the short name. Set the package context
while calling the init function, as the dynamic loader does, so the
module gets the full name from the spec.
(cherry picked from commit 0486228)

Co-authored-by: Itamar Oren itamarost@gmail.com

…func() (pythonGH-157387)

A single-phase init function that creates its module using only the
last component of a dotted name (as pybind11 does for submodules) got
a module whose __name__ was the short name.  Set the package context
while calling the init function, as the dynamic loader does, so the
module gets the full name from the spec.
(cherry picked from commit 0486228)

Co-authored-by: Itamar Oren <itamarost@gmail.com>
@read-the-docs-community

Copy link
Copy Markdown

@brettcannon
brettcannon removed their request for review October 13, 2026 23:30
@encukou
encukou merged commit 33a05de into python:3.15 Oct 14, 2026
56 checks passed
@miss-islington
miss-islington deleted the backport-0486228-3.15 branch October 14, 2026 11:49
meta-codesync Bot pushed a commit to facebookincubator/MetaPython that referenced this pull request Oct 15, 2026
…nitfunc()

Summary:
Backport of the upstream fix (python/cpython#157387, 3.15 backport python/cpython#159316), folded into the `05-native-python-api` patch that carries our 3.14 backport of `PyImport_CreateModuleFromInitfunc`.

A single-phase init function that creates its module using only the last component of a dotted name (as pybind11 2.13 does for `PYBIND11_MODULE` extensions inside a package) got a module whose `__name__` was the short name, so `def_submodule` registered submodules under the wrong `sys.modules` keys and `from pkg.ext.sub import x` failed with "`pkg.ext` is not a package". 571 failures in V66 of the py3.14 canary (D82323768) carry this signature.

Reviewed By: alexmalyshev

Differential Revision: D119701167

fbshipit-source-id: dc50c5ece93752c069548588545eee6526181cad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants