Title: Accessing one lazily imported submodule (`lazy import pkg.a`) also imports a later imported `pkg.b` · Issue #158140 · python/cpython · GitHub
Open Graph Title: Accessing one lazily imported submodule (`lazy import pkg.a`) also imports a later imported `pkg.b` · Issue #158140 · python/cpython
X Title: Accessing one lazily imported submodule (`lazy import pkg.a`) also imports a later imported `pkg.b` · Issue #158140 · python/cpython
Description: Bug report Bug description: If we do a lazy import of two submodules in the same package tree (like pkg.a and pkg.b), then accessing pkg.a will cause pkg.b to get imported first. I think this is because pkg gets bound specifically to a l...
Open Graph Description: Bug report Bug description: If we do a lazy import of two submodules in the same package tree (like pkg.a and pkg.b), then accessing pkg.a will cause pkg.b to get imported first. I think this is be...
X Description: Bug report Bug description: If we do a lazy import of two submodules in the same package tree (like pkg.a and pkg.b), then accessing pkg.a will cause pkg.b to get imported first. I think this is be...
Opengraph URL: https://github.com/python/cpython/issues/158140
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Accessing one lazily imported submodule (`lazy import pkg.a`) also imports a later imported `pkg.b`","articleBody":"# Bug report\n\n### Bug description:\n\nIf we do a lazy import of two submodules in the same package tree (like `pkg.a` and `pkg.b`), then accessing `pkg.a` will cause `pkg.b` to get imported first. I think this is because pkg gets bound specifically to a lazy_import object for `pkg.b`. (In fact, just accessing `pkg` *also* imports `pkg.b`).\n\n`main.py`:\n```python\nlazy import pkg.a\nlazy import pkg.b\n\nprint(globals()['pkg']) # \u003clazy_import 'pkg.b'>\n\npkg.a # triggers import of pkg (of course), pkg.b (sketchy!!), pkg.a (of course)\n```\n\n```\npkg/\n├── __init__.py # print(\"pkg\")\n├── a.py # print(\"pkg.a\")\n└── b.py # print(\"pkg.b\")\n```\n\nThis prints:\n```\n\u003clazy_import 'pkg.b'>\npkg\npkg.b\npkg.a\n```\n\n\n### CPython versions tested on:\n\n3.15\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-158491\n* gh-158521\n* gh-158613\n* gh-158815\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/msullivan","@type":"Person","name":"msullivan"},"datePublished":"2026-09-24T22:42:00Z","url":"https://github.com/python/cpython/issues/158140"}
| 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:fd2dae37-9bc9-4909-331e-b6df60ba43f5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A41C:5D487:1274C2D:1877835:6B01EEE5 |
| html-safe-nonce | 78dabf2e438c9bf83b75845925c773d24f347be928b574f571ae7a4f825cde01 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDFDOjVENDg3OjEyNzRDMkQ6MTg3NzgzNTo2QjAxRUVFNSIsInZpc2l0b3JfaWQiOiI0OTAzNjU5Mzk5MjIxMDQwMzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 607f68b27373d6f037c79fa18fec8e1e71b69839317ae5a6b716ea8c94d63740 |
| hovercard-subject-tag | issue:5575482628 |
| 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/158140/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1650ef8bddb8492cc454f5b956e5f707544dc3b637bae063a6f41443409fd815/python/cpython/issues/158140 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1650ef8bddb8492cc454f5b956e5f707544dc3b637bae063a6f41443409fd815/python/cpython/issues/158140 |
| og:image:alt | Bug report Bug description: If we do a lazy import of two submodules in the same package tree (like pkg.a and pkg.b), then accessing pkg.a will cause pkg.b to get imported first. I think this is be... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | msullivan |
| 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