Title: `__lazy_import__` crashes with user-defined filters · Issue #144851 · python/cpython · GitHub
Open Graph Title: `__lazy_import__` crashes with user-defined filters · Issue #144851 · python/cpython
X Title: `__lazy_import__` crashes with user-defined filters · Issue #144851 · python/cpython
Description: Crash report Bug description: This crashes from an assertion error, only when __lazy_import__ is called directly: import sys def li_filter(importing_module: str, imported_module: str, fromlist: tuple[str, ...]) -> bool: return False sys....
Open Graph Description: Crash report Bug description: This crashes from an assertion error, only when __lazy_import__ is called directly: import sys def li_filter(importing_module: str, imported_module: str, fromlist: tup...
X Description: Crash report Bug description: This crashes from an assertion error, only when __lazy_import__ is called directly: import sys def li_filter(importing_module: str, imported_module: str, fromlist: tup...
Opengraph URL: https://github.com/python/cpython/issues/144851
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`__lazy_import__` crashes with user-defined filters","articleBody":"# Crash report\n\n### Bug description:\n\nThis crashes from an assertion error, only when `__lazy_import__` is called directly:\n\n```python\nimport sys\n\ndef li_filter(importing_module: str, imported_module: str, fromlist: tuple[str, ...]) -\u003e bool:\n return False\n\nsys.set_lazy_imports_filter(li_filter)\n\n__lazy_import__('wave')\n```\n\nMoved from https://github.com/LazyImportsCabal/cpython/issues/45 (couldn't have transferred it).\n\nThe compiler would always put a `LOAD_CONST (None)` before any `IMPORT_NAME` for imports without `from`, which is why this crash never happens in a regular `lazy import`.\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-144852\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/johnslavik","@type":"Person","name":"johnslavik"},"datePublished":"2026-02-15T21:37:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/144851/cpython/issues/144851"}
| 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:eba994ec-d1f4-a45c-08fc-0001b752080b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9760:13EE66:226B303:3136811:6A50FE36 |
| html-safe-nonce | a3fb8c540a0e203ab3852723f5adc87db9cb95235511dfac604bc42d90679417 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzYwOjEzRUU2NjoyMjZCMzAzOjMxMzY4MTE6NkE1MEZFMzYiLCJ2aXNpdG9yX2lkIjoiMjM0NDQxMjcxMDY2ODY2NDM3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 856717ea442ba759477f84829e138cd9c9bc45ae4c9ce29da248247bafbba61e |
| hovercard-subject-tag | issue:3944982498 |
| 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/144851/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8b2bdf6c81459ba1fd7a8445de267283dc387488857b80aa3b8f05ba67b606c2/python/cpython/issues/144851 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8b2bdf6c81459ba1fd7a8445de267283dc387488857b80aa3b8f05ba67b606c2/python/cpython/issues/144851 |
| og:image:alt | Crash report Bug description: This crashes from an assertion error, only when __lazy_import__ is called directly: import sys def li_filter(importing_module: str, imported_module: str, fromlist: tup... |
| 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 | 38906a4da4e3e9fd88dfeacee232f5932c0c5f7495de3b4efc53ddfac7173d12 |
| 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 | 90441ea9b98e7491aa6ebcd135fccce4e2396f48 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width