Title: When re-importing a submodule lazily after removing it, it's never added back to sys.modules. · Issue #151408 · python/cpython · GitHub
Open Graph Title: When re-importing a submodule lazily after removing it, it's never added back to sys.modules. · Issue #151408 · python/cpython
X Title: When re-importing a submodule lazily after removing it, it's never added back to sys.modules. · Issue #151408 · python/cpython
Description: Bug report Bug description: While working on setting up testing infra for lazy_imports=all, I came across this test failure in test_trace. It appears that after importing a submodule, deleting said submodule, and then lazy importing it a...
Open Graph Description: Bug report Bug description: While working on setting up testing infra for lazy_imports=all, I came across this test failure in test_trace. It appears that after importing a submodule, deleting said...
X Description: Bug report Bug description: While working on setting up testing infra for lazy_imports=all, I came across this test failure in test_trace. It appears that after importing a submodule, deleting said...
Opengraph URL: https://github.com/python/cpython/issues/151408
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"When re-importing a submodule lazily after removing it, it's never added back to sys.modules.","articleBody":"# Bug report\n\n### Bug description:\n\nWhile working on setting up testing infra for `lazy_imports=all`, I came across [this test failure](https://github.com/python/cpython/actions/runs/27367951965/job/80872381191#step:11:7982) in test_trace. It appears that after importing a submodule, deleting said submodule, and then lazy importing it again--the module doesn't make it's way back into `sys.modules`.\n\nExample failing code snippet:\n```python\nimport sys\nmodname = \"test.test_lazy_import.data.pkg.bar\"\nimport test.test_lazy_import.data.pkg.bar\ndel sys.modules[modname]\nlazy import test.test_lazy_import.data.pkg.bar # the issue is also seen when using lazy from\nbar.f()\nassert modname in sys.modules # False\n```\n\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-151411\n* gh-151412\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/brittanyrey","@type":"Person","name":"brittanyrey"},"datePublished":"2026-06-12T15:21:42Z","url":"https://github.com/python/cpython/issues/151408"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:190372ab-811f-9f06-940c-8939ced90e68 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 88EC:16E4ED:68B485:83B9CA:6B02099A |
| html-safe-nonce | 0383d4a42062cf7e7998c9ddced23b5bea187a9dd095d75236e4b7b4f14b85ab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEVDOjE2RTRFRDo2OEI0ODU6ODNCOUNBOjZCMDIwOTlBIiwidmlzaXRvcl9pZCI6IjExMTM1ODM0MTk5MDE3NDE0NjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9af4ee9e5fff5bf3f3d70712835f44ce41257ad24febfabba5712c3841052779 |
| hovercard-subject-tag | issue:4650440875 |
| 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/151408/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ad9216c53e7538b28c0bbe5eead7c1b85cd4f0507d82e0e0f20b02639f1a4886/python/cpython/issues/151408 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ad9216c53e7538b28c0bbe5eead7c1b85cd4f0507d82e0e0f20b02639f1a4886/python/cpython/issues/151408 |
| og:image:alt | Bug report Bug description: While working on setting up testing infra for lazy_imports=all, I came across this test failure in test_trace. It appears that after importing a submodule, deleting said... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brittanyrey |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width