Title: Specialize `AttributeError` exceptions from lazy import objects · Issue #154196 · python/cpython · GitHub
Open Graph Title: Specialize `AttributeError` exceptions from lazy import objects · Issue #154196 · python/cpython
X Title: Specialize `AttributeError` exceptions from lazy import objects · Issue #154196 · python/cpython
Description: Feature or enhancement Consider specializing AttributeError exceptions when custom attributes are accessed on lazy import objects, typically meaning that a lazy import is believed to have been reified when it still isn't reified. It's fa...
Open Graph Description: Feature or enhancement Consider specializing AttributeError exceptions when custom attributes are accessed on lazy import objects, typically meaning that a lazy import is believed to have been reif...
X Description: Feature or enhancement Consider specializing AttributeError exceptions when custom attributes are accessed on lazy import objects, typically meaning that a lazy import is believed to have been reif...
Opengraph URL: https://github.com/python/cpython/issues/154196
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Specialize `AttributeError` exceptions from lazy import objects","articleBody":"# Feature or enhancement\n\nConsider specializing `AttributeError` exceptions when custom attributes are accessed on lazy import objects, typically meaning that a lazy import is believed to have been reified when it still isn't reified. It's fairly easy to specialize the exception, so if such accesses are realistic, this might make sense.\n\n## Example\n\n```py\nlazy import asyncio\n\nglobals()[\"asyncio\"].Task\n```\n\nThis is the current traceback:\n```\nTraceback (most recent call last):\n File \"/Users/bartosz.slawecki/pydev/gh-153785/t.py\", line 3, in \u003cmodule>\n globals()[\"asyncio\"].Task\nAttributeError: 'lazy_import' object has no attribute 'Task'\n```\n\n**This is the proposal:**\n```\nTraceback (most recent call last):\n File \"/Users/bartosz.slawecki/pydev/gh-153785/t.py\", line 3, in \u003cmodule>\n globals()[\"asyncio\"].Task\nAttributeError: cannot access attribute 'Task' on unresolved lazy import 'asyncio'\n```\n\nI do not insist on this being implemented, but we can discuss if it is potentially useful or not. \nWorking prototype: https://github.com/python/cpython/compare/main...johnslavik:gh-154196\n\n## Additional context\n\nThis was reported by @vstinner in https://github.com/python/cpython/pull/153786#pullrequestreview-4728765088.\n\nOpened as a separate issue because the specialization of lazy import `AttributeError` exceptions, to my mind, does not belong to that pull request.\n\n(The mentioned PR was meant for rare paths involving user-space raises of `AttributeError`, either with attribute name only or with no arguments.)\n\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154688\n* gh-155899\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/johnslavik","@type":"Person","name":"johnslavik"},"datePublished":"2026-07-19T20:27:23Z","url":"https://github.com/python/cpython/issues/154196"}
| 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:a9a9db05-5482-be3a-f45e-2913ae651ee5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 83A4:2C4BED:40C1EEA:522C958:6B021F1E |
| html-safe-nonce | 68a6adb0a43dcb3c407f7b5238169ee60ac6cbfe062719dd9ae0e408fbc9174b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4M0E0OjJDNEJFRDo0MEMxRUVBOjUyMkM5NTg6NkIwMjFGMUUiLCJ2aXNpdG9yX2lkIjoiMTE1MTI5MDcyMDIwNDc1ODgxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 88b7c5a1447f04a92be20f6b0b7d3b5479d4b307df07d30521bc7f2d69d4476b |
| hovercard-subject-tag | issue:4924267758 |
| 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/154196/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c7ff870c72a529ffa74455b552dcefa9729bfa0e744d23bce3146147fa4709d6/python/cpython/issues/154196 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c7ff870c72a529ffa74455b552dcefa9729bfa0e744d23bce3146147fa4709d6/python/cpython/issues/154196 |
| og:image:alt | Feature or enhancement Consider specializing AttributeError exceptions when custom attributes are accessed on lazy import objects, typically meaning that a lazy import is believed to have been reif... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | johnslavik |
| 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