Title: `_PyImport_SwapPackageContext` would be helpful if exposed · Issue #139227 · python/cpython · GitHub
Open Graph Title: `_PyImport_SwapPackageContext` would be helpful if exposed · Issue #139227 · python/cpython
X Title: `_PyImport_SwapPackageContext` would be helpful if exposed · Issue #139227 · python/cpython
Description: Feature or enhancement In Nuitka, we have our own meta-path-based loader, which loads packages that contain extension modules with custom code that emulates the load process. For an extension module in a package, we used to set _Py_Packa...
Open Graph Description: Feature or enhancement In Nuitka, we have our own meta-path-based loader, which loads packages that contain extension modules with custom code that emulates the load process. For an extension modul...
X Description: Feature or enhancement In Nuitka, we have our own meta-path-based loader, which loads packages that contain extension modules with custom code that emulates the load process. For an extension modul...
Opengraph URL: https://github.com/python/cpython/issues/139227
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`_PyImport_SwapPackageContext` would be helpful if exposed","articleBody":"# Feature or enhancement\n\nIn Nuitka, we have our own meta-path-based loader, which loads packages that contain extension modules with custom code that emulates the load process. For an extension module in a package, we used to set `_Py_PackageContext`, which has since been removed. Currently, `_PyRuntime.imports.pkgcontext` is not used because [we fall back](https://github.com/python/cpython/blob/a756a4b95341cda63298fb5628b56c32f43f4f1e/Python/import.c#L785-L789) to a thread-local `pkgcontext` variable, which Nuitka cannot access on Windows or where static linking to Python is not available.\n\nThis leads to some issues when Nuitka goes to load extensions that are stored in a submodule or create submodules, because the package context is not correct. For example, an extension module under `x.y` will create submodule `z` as `y.z` rather than `x.y.z`. There are currently some workarounds to repair the damage, but this is tedious and sometimes unreliable. If `_PyImport_SwapPackageContext` were exposed, Nuitka could just call that and make `PyModule_Create` know what package it lives in.\n\nNuitka doesn't need `_PyImport_SwapPackageContext` to be exposed as public or `PyUnstable`, we would just like to have it available in the ABI under `PyAPI_FUNC`. It would be very helpful if this could happen before 3.14.0, but that's up to Hugo.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-139228\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ZeroIntensity","@type":"Person","name":"ZeroIntensity"},"datePublished":"2025-09-22T11:11:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/139227/cpython/issues/139227"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a754b2bc-36da-fddb-392f-342a01b90927 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E4BE:30E6E5:1C40FBF:26A12D8:696ABD3F |
| html-safe-nonce | cef1a2e06db49f689e12cea6f86c3958ef318bcb730aad59146b1bf3d2a88af4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNEJFOjMwRTZFNToxQzQwRkJGOjI2QTEyRDg6Njk2QUJEM0YiLCJ2aXNpdG9yX2lkIjoiMjM3NDIxMDI3MDMzNTI1MzgyMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7376f09bf00da01eca210a61c2cf74b575ac690b68f4fbedd2497425e85f9cdd |
| hovercard-subject-tag | issue:3440414470 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/139227/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8061654e98de882a3b492c5302b8b8c9d43ea29bc4898ca1ae12cadc09b1b704/python/cpython/issues/139227 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8061654e98de882a3b492c5302b8b8c9d43ea29bc4898ca1ae12cadc09b1b704/python/cpython/issues/139227 |
| og:image:alt | Feature or enhancement In Nuitka, we have our own meta-path-based loader, which loads packages that contain extension modules with custom code that emulates the load process. For an extension modul... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ZeroIntensity |
| hostname | github.com |
| expected-hostname | github.com |
| None | 46ce962e0e18113ea447391b6ace8b02d4d2861e57b4fbab3658698f73d8855b |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 30300f30bb3949de255e84a146706a3bdb5c19c9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width