Title: Lazy imports may leave phantom unresolvable attributes in module · Issue #150052 · python/cpython · GitHub
Open Graph Title: Lazy imports may leave phantom unresolvable attributes in module · Issue #150052 · python/cpython
X Title: Lazy imports may leave phantom unresolvable attributes in module · Issue #150052 · python/cpython
Description: Bug description: @pablogsal brought this up at the sprints today. When doing "from .. import .." we track the "from" values to publish when on the module when it finally gets imported. We have no way to distinguish whether the values act...
Open Graph Description: Bug description: @pablogsal brought this up at the sprints today. When doing "from .. import .." we track the "from" values to publish when on the module when it finally gets imported. We have no w...
X Description: Bug description: @pablogsal brought this up at the sprints today. When doing "from .. import .." we track the "from" values to publish when on the module when it finally gets im...
Opengraph URL: https://github.com/python/cpython/issues/150052
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Lazy imports may leave phantom unresolvable attributes in module","articleBody":"### Bug description:\n@pablogsal brought this up at the sprints today. When doing \"from .. import ..\" we track the \"from\" values to publish when on the module when it finally gets imported. We have no way to distinguish whether the values actually exist, if they're values within the package we're importing from, or if they're subpackages. When the module is imported we publish these values as `LazyImportObject`s on the module. Because we don't know if they exist or if they're subpackages they all get published as long as they don't already exist in the module potentially leaving some cruft around.\n\nInitially this feels like it's \"by design\". But there's a few alternatives we should consider:\n1) Remove the `LazyImportObject` from the module if the value is attempted to be resolved but doesn't exist\n2) Switch to instead of publishing the value update `_Py_module_getattro_impl` to return these values. This is maybe more in the spirit of the changes we've made to push things into the module object in general. We'd publish nothing into the module but it would magically become available if we resolve it and then presumably we'd publish it into the module.\n\n```\n>>> lazy from json import noway\n>>> import json\n>>> dir(json)\n['JSONDecodeError', 'JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__getattr__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_default_decoder', '_default_encoder', 'codecs', 'decoder', 'detect_encoding', 'dump', 'dumps', 'encoder', 'load', 'loads', 'noway', 'scanner']\n>>> json.noway\nTraceback (most recent call last):\n File \"\u003cfrozen importlib._bootstrap>\", line 1319, in _find_and_load_unlocked\nImportError: deferred import of 'json.noway' raised an exception during resolution\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"\u003cpython-input-3>\", line 1, in \u003cmodule>\n json.noway\nImportError: cannot import name 'noway' from 'json' (/home/dinoviehland/cpython_upstream/Lib/json/__init__.py)\n>>> dir(json)\n['JSONDecodeError', 'JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__getattr__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_default_decoder', '_default_encoder', 'codecs', 'decoder', 'detect_encoding', 'dump', 'dumps', 'encoder', 'load', 'loads', 'noway', 'scanner']\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-150054\n* gh-150055\n* gh-150744\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/DinoV","@type":"Person","name":"DinoV"},"datePublished":"2026-05-19T03:31:59Z","url":"https://github.com/python/cpython/issues/150052"}
| 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:40574b53-9d16-bb56-565e-35a15611749a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E60A:1D20B7:2BDAE45:3798C5F:6B01E3F5 |
| html-safe-nonce | 10986f3431269d49b81813fea65803a4bd9ad705b3698665a8d7a2c32add61b5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjBBOjFEMjBCNzoyQkRBRTQ1OjM3OThDNUY6NkIwMUUzRjUiLCJ2aXNpdG9yX2lkIjoiNzA3NDQ3MTE0NTkzMTY2MjMyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d22a45ba42ad48401aa5abc02fcd71863dfbc1df45e0037f59c70ec2e9caf0e2 |
| hovercard-subject-tag | issue:4474180312 |
| 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/150052/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c64fb3e94a104354de36ff7eae27e541bbadeb7d7955de5b2161edffffc6cbd4/python/cpython/issues/150052 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c64fb3e94a104354de36ff7eae27e541bbadeb7d7955de5b2161edffffc6cbd4/python/cpython/issues/150052 |
| og:image:alt | Bug description: @pablogsal brought this up at the sprints today. When doing "from .. import .." we track the "from" values to publish when on the module when it finally gets imported. We have no w... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DinoV |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width