Title: Names that have been resolved are not consistently removed from sys.lazy_modules · Issue #155695 · python/cpython · GitHub
Open Graph Title: Names that have been resolved are not consistently removed from sys.lazy_modules · Issue #155695 · python/cpython
X Title: Names that have been resolved are not consistently removed from sys.lazy_modules · Issue #155695 · python/cpython
Description: Bug report Bug description: I'm slightly hesitant to raise this because there's still discussion over what sys.lazy_modules should be. The documentation for sys.lazy_modules currently states: When a lazily imported module is accessed for...
Open Graph Description: Bug report Bug description: I'm slightly hesitant to raise this because there's still discussion over what sys.lazy_modules should be. The documentation for sys.lazy_modules currently states: When ...
X Description: Bug report Bug description: I'm slightly hesitant to raise this because there's still discussion over what sys.lazy_modules should be. The documentation for sys.lazy_modules currently state...
Opengraph URL: https://github.com/python/cpython/issues/155695
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Names that have been resolved are not consistently removed from sys.lazy_modules","articleBody":"# Bug report\n\n### Bug description:\n\nI'm slightly hesitant to raise this because there's still discussion over what `sys.lazy_modules` should be. The documentation for `sys.lazy_modules` currently states:\n\n> When a lazily imported module is accessed for the first time, its name is removed from this set.\n\nIn at least two cases I'm aware of names are not being removed. Names may also not be modules, but I'd consider that a documentation issue while I believe the failure to remove names is a bug.\n\n---\n\nNames of modules that have previously been resolved will be re-added, but not removed when resolved again.\n\n```python\nimport sys\nmods = sys.lazy_modules.copy()\ndef get_lazy():\n return sorted(sys.lazy_modules - mods)\n\nlazy import x # added\nprint(get_lazy())\nx # removed\nprint(get_lazy())\nlazy import x # added again\nx # not removed\nprint(get_lazy())\n```\n\n```\n['x']\n[]\n['x']\n```\n\nHere I think the issue is adding `x` back to `sys.lazy_modules` when it's already in `sys.modules`.\n\n---\n\nNames that are not modules are not removed:\n\n```python\nimport sys\nmods = sys.lazy_modules.copy()\ndef get_lazy():\n return sorted(sys.lazy_modules - mods)\n\nlazy from x import X\nprint(get_lazy())\nX\nprint(get_lazy()) # Should be empty\n```\n\n```\n['x', 'x.X']\n['x.X']\n```\n\n\n### CPython versions tested on:\n\n3.15, CPython main branch\n\n### Operating systems tested on:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-157714\n* gh-158607\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/DavidCEllis","@type":"Person","name":"DavidCEllis"},"datePublished":"2026-08-13T11:10:44Z","url":"https://github.com/python/cpython/issues/155695"}
| 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:2f034388-6783-68be-cbe2-083b2525018f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BEFC:FC5BE:33C291F:44C82E1:6B01F77B |
| html-safe-nonce | 4d27de0eea7a749329fb4e93475f5b29450da56b8b44af70509c73cd911c2fa9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRUZDOkZDNUJFOjMzQzI5MUY6NDRDODJFMTo2QjAxRjc3QiIsInZpc2l0b3JfaWQiOiIxMDkyOTExNzQyMzA2MDg4ODI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 117b5a7aeef5c84197362426af4ff4433c7a715af9fc4a213845054a2f6025d4 |
| hovercard-subject-tag | issue:5140740106 |
| 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/155695/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4a3af5f028e071dbba9b899cd93f3e4103ed4765f45541cc739c4e55ed0d239c/python/cpython/issues/155695 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4a3af5f028e071dbba9b899cd93f3e4103ed4765f45541cc739c4e55ed0d239c/python/cpython/issues/155695 |
| og:image:alt | Bug report Bug description: I'm slightly hesitant to raise this because there's still discussion over what sys.lazy_modules should be. The documentation for sys.lazy_modules currently states: When ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DavidCEllis |
| 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