René's URL Explorer Experiment


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

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@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-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2f034388-6783-68be-cbe2-083b2525018f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBEFC:FC5BE:33C291F:44C82E1:6B01F77B
html-safe-nonce4d27de0eea7a749329fb4e93475f5b29450da56b8b44af70509c73cd911c2fa9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRUZDOkZDNUJFOjMzQzI5MUY6NDRDODJFMTo2QjAxRjc3QiIsInZpc2l0b3JfaWQiOiIxMDkyOTExNzQyMzA2MDg4ODI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac117b5a7aeef5c84197362426af4ff4433c7a715af9fc4a213845054a2f6025d4
hovercard-subject-tagissue:5140740106
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/155695/issue_layout
twitter:imagehttps://opengraph.githubassets.com/4a3af5f028e071dbba9b899cd93f3e4103ed4765f45541cc739c4e55ed0d239c/python/cpython/issues/155695
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/4a3af5f028e071dbba9b899cd93f3e4103ed4765f45541cc739c4e55ed0d239c/python/cpython/issues/155695
og:image:altBug 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:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameDavidCEllis
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/155695#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F155695
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F155695
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/155695
Reloadhttps://github.com/python/cpython/issues/155695
Reloadhttps://github.com/python/cpython/issues/155695
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/155695
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/155695
Names that have been resolved are not consistently removed from sys.lazy_moduleshttps://github.com/python/cpython/issues/155695#top
https://github.com/johnslavik
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
release-blockerhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22release-blocker%22
topic-lazy-importshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-lazy-imports%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/DavidCEllis
DavidCEllishttps://github.com/DavidCEllis
on Aug 13, 2026https://github.com/python/cpython/issues/155695#issue-5140740106
gh-155695: Remove resolved names from sys.lazy_modules more consistently #157714https://github.com/python/cpython/pull/157714
[3.15] gh-155695: Remove resolved names from sys.lazy_modules more consistently (GH-157714) #158607https://github.com/python/cpython/pull/158607
DavidCEllishttps://github.com/DavidCEllis
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
topic-lazy-importshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-lazy-imports%22
on Aug 13, 2026https://github.com/python/cpython/issues/155695#event-29395915221
picnixzhttps://github.com/picnixz
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Aug 13, 2026https://github.com/python/cpython/issues/155695#event-29427437568
https://github.com/prithviraj-chaudhuri
prithviraj-chaudhurihttps://github.com/prithviraj-chaudhuri
on Aug 28, 2026https://github.com/python/cpython/issues/155695#issuecomment-5457620419
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Sep 2, 2026https://github.com/python/cpython/issues/155695#issuecomment-5515214033
https://github.com/prithviraj-chaudhuri
prithviraj-chaudhurihttps://github.com/prithviraj-chaudhuri
on Sep 9, 2026https://github.com/python/cpython/issues/155695#issuecomment-5595930346
https://github.com/DavidCEllis
DavidCEllishttps://github.com/DavidCEllis
on Sep 10, 2026https://github.com/python/cpython/issues/155695#issuecomment-5617201653
@picnixzhttps://github.com/picnixz
The documentationhttps://docs.python.org/3.15/library/sys.html#sys.lazy_modules
johnslavikhttps://github.com/johnslavik
johnslavikhttps://github.com/johnslavik
johnslavikhttps://github.com/johnslavik
on Sep 10, 2026https://github.com/python/cpython/issues/155695#event-30896874721
https://github.com/psyedgufran-svg
psyedgufran-svghttps://github.com/psyedgufran-svg
on Sep 10, 2026https://github.com/python/cpython/issues/155695#issuecomment-5617853197
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Sep 10, 2026https://github.com/python/cpython/issues/155695#issuecomment-5618450735
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Sep 10, 2026https://github.com/python/cpython/issues/155695#issuecomment-5618461167
@DinoVhttps://github.com/DinoV
@pablogsalhttps://github.com/pablogsal
https://github.com/johnslavik
johnslavikhttps://github.com/johnslavik
on Sep 10, 2026https://github.com/python/cpython/issues/155695#issuecomment-5625181322
creates a proxy and adds x to sys.lazy_moduleshttps://github.com/python/cpython/blob/ee521e8ac19ad012ebc4e1b3e71b369988a9b9f8/Python/import.c#L4603-L4614
calls the ordinary import machineryhttps://github.com/python/cpython/blob/ee521e8ac19ad012ebc4e1b3e71b369988a9b9f8/Python/import.c#L3976-L3999
cache lookup returns the existing modulehttps://github.com/python/cpython/blob/ee521e8ac19ad012ebc4e1b3e71b369988a9b9f8/Python/import.c#L4220-L4257
lazy from x import X already has an eager cache fast pathhttps://github.com/python/cpython/blob/ee521e8ac19ad012ebc4e1b3e71b369988a9b9f8/Python/ceval.c#L3324-L3350
_find_and_load_unlocked() calls _imp._set_lazy_attributes() after loadinghttps://github.com/python/cpython/blob/ee521e8ac19ad012ebc4e1b3e71b369988a9b9f8/Lib/importlib/_bootstrap.py#L1302-L1321
that function discards the loaded module's name from sys.lazy_moduleshttps://github.com/python/cpython/blob/ee521e8ac19ad012ebc4e1b3e71b369988a9b9f8/Python/import.c#L5646-L5656
the parent module namehttps://github.com/python/cpython/blob/ee521e8ac19ad012ebc4e1b3e71b369988a9b9f8/Python/import.c#L4610-L4624
the qualified imported name, such as x.Xhttps://github.com/python/cpython/blob/ee521e8ac19ad012ebc4e1b3e71b369988a9b9f8/Python/import.c#L4425-L4443
https://github.com/johnslavik
johnslavikhttps://github.com/johnslavik
on Sep 11, 2026https://github.com/python/cpython/issues/155695#issuecomment-5627600451
johnslavikhttps://github.com/johnslavik
on Sep 11, 2026https://github.com/python/cpython/issues/155695#event-30940409667
https://github.com/brittanyrey
brittanyreyhttps://github.com/brittanyrey
on Sep 17, 2026https://github.com/python/cpython/issues/155695#issuecomment-5722020437
@pablogsalhttps://github.com/pablogsal
https://github.com/johnslavik
johnslavikhttps://github.com/johnslavik
on Sep 17, 2026https://github.com/python/cpython/issues/155695#issuecomment-5722248675
@brittanyreyhttps://github.com/brittanyrey
pablogsalhttps://github.com/pablogsal
on Sep 26, 2026https://github.com/python/cpython/issues/155695#event-31907366238
pythongh-155695: Track cached exports without invoking spec callbackshttps://github.com/brittanyrey/cpython/commit/44ebbaae638f56781ceed4478bdb70c4b28d70f0
pythongh-155695https://github.com/python/cpython/issues/155695
44ebbaahttps://github.com/brittanyrey/cpython/commit/44ebbaae638f56781ceed4478bdb70c4b28d70f0
pythongh-155695: Read initialization flags without materializing spec…https://github.com/brittanyrey/cpython/commit/5fa018a30287f44a3846366bbd27bc7b3ce3b513
pythongh-155695https://github.com/python/cpython/issues/155695
5fa018ahttps://github.com/brittanyrey/cpython/commit/5fa018a30287f44a3846366bbd27bc7b3ce3b513
pythongh-155695: Keep lazy-module state inspection conservativehttps://github.com/brittanyrey/cpython/commit/ce8c909750db1d40cd87f959bfb67a9543eee5e1
pythongh-155695https://github.com/python/cpython/issues/155695
ce8c909https://github.com/brittanyrey/cpython/commit/ce8c909750db1d40cd87f959bfb67a9543eee5e1
pythongh-155695: Simplify lazy module bookkeepinghttps://github.com/brittanyrey/cpython/commit/83ac500b1a4ab931eadb456a5e82749531812732
pythongh-155695https://github.com/python/cpython/issues/155695
83ac500https://github.com/brittanyrey/cpython/commit/83ac500b1a4ab931eadb456a5e82749531812732
pythongh-155695: Preserve import behavior in lazy module trackinghttps://github.com/brittanyrey/cpython/commit/ad36b560b9ab1f5e073b5ecb3d6c2d1e132dce42
pythongh-155695https://github.com/python/cpython/issues/155695
ad36b56https://github.com/brittanyrey/cpython/commit/ad36b560b9ab1f5e073b5ecb3d6c2d1e132dce42
hugovkhttps://github.com/hugovk
release-blockerhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22release-blocker%22
on Sep 30, 2026https://github.com/python/cpython/issues/155695#event-32205274629
github-project-automationhttps://github.com/apps/github-project-automation
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
on Sep 30, 2026https://github.com/python/cpython/issues/155695#event-32330198191
github-project-automationhttps://github.com/apps/github-project-automation
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
on Sep 30, 2026https://github.com/python/cpython/issues/155695
hugovkhttps://github.com/hugovk
on Oct 2, 2026https://github.com/python/cpython/issues/155695#event-32348599261
gh-155695: Remove resolved names from sys.lazy_modules more consisten…https://github.com/python/cpython/commit/be87a85e2fb0cc22e6c4292ecec1bf7e3d0d3ace
gh-155695https://github.com/python/cpython/issues/155695
be87a85https://github.com/python/cpython/commit/be87a85e2fb0cc22e6c4292ecec1bf7e3d0d3ace
Yhg1shttps://github.com/Yhg1s
on Oct 2, 2026https://github.com/python/cpython/issues/155695#event-32351454676
[3.15] gh-155695: Remove resolved names from sys.lazy_modules more co…https://github.com/python/cpython/commit/c2eb1a85910b917d398768423b53e518c1e362da
gh-155695https://github.com/python/cpython/issues/155695
c2eb1a8https://github.com/python/cpython/commit/c2eb1a85910b917d398768423b53e518c1e362da
hugovkhttps://github.com/hugovk
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Oct 2, 2026https://github.com/python/cpython/issues/155695#event-32351985709
Kronuzhttps://github.com/Kronuz
on Oct 5, 2026https://github.com/python/cpython/issues/155695#event-32537047080
[3.15] pythongh-155695: Remove resolved names from sys.lazy_modules m…https://github.com/Kronuz/cpython/commit/c305e7e8bb7cabf888e96c428c5161ea080be76b
pythongh-155695https://github.com/python/cpython/issues/155695
c305e7ehttps://github.com/Kronuz/cpython/commit/c305e7e8bb7cabf888e96c428c5161ea080be76b
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/155695
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/155695
johnslavikhttps://github.com/johnslavik
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
release-blockerhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22release-blocker%22
topic-lazy-importshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-lazy-imports%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
Release and Deferred blockers 🚫https://github.com/orgs/python/projects/2
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.