Title: Should we test `-X lazy_imports=all` more? · Issue #149640 · python/cpython · GitHub
Open Graph Title: Should we test `-X lazy_imports=all` more? · Issue #149640 · python/cpython
X Title: Should we test `-X lazy_imports=all` more? · Issue #149640 · python/cpython
Description: Bug report Bug description: Inspired by #149321 I decided to see how well the test suite works with PYTHON_LAZY_IMPORTS=all / -X lazy_imports=all, which makes all imports lazy. It's nowhere near as bad as the none option that we're consi...
Open Graph Description: Bug report Bug description: Inspired by #149321 I decided to see how well the test suite works with PYTHON_LAZY_IMPORTS=all / -X lazy_imports=all, which makes all imports lazy. It's nowhere near as...
X Description: Bug report Bug description: Inspired by #149321 I decided to see how well the test suite works with PYTHON_LAZY_IMPORTS=all / -X lazy_imports=all, which makes all imports lazy. It's nowhere nea...
Opengraph URL: https://github.com/python/cpython/issues/149640
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Should we test `-X lazy_imports=all` more?","articleBody":"# Bug report\n\n### Bug description:\n\nInspired by #149321 I decided to see how well the test suite works with `PYTHON_LAZY_IMPORTS=all` / `-X lazy_imports=all`, which makes all imports lazy. It's nowhere near as bad as the `none` option that we're considering removing, but a few parts of the stdlib are broken, and it seems worth considering if we want to fix these.\n\nConcrete issues I noticed:\n- #144957 breaks test_typing\n- `test_unittest` fails because `unittest.main` becomes a module instead of a function.\n- `test_struct` is broken because of a test that does `exec(\"import struct\")` in a function; lazy imports are disallowed within functions. Similar issues affect `test_enum`, `test_traceback`, and `test_future`.\n- `test_symtable` is broken because it fills its `_flags` list by iterating over `globals()`, which means it starts containing lazy import marker objects. Similarly `test_inspect` breaks because it iterates over `vars()` of a module.\n\nA few tests fail for legitimate reasons; `test_compileall` tests that an import triggers pyc compilation; `test_builtin` asserts that `__import__` is used when in fact `__lazy_import__` gets used.\n\nFull list of failed modules on my machine:\n\n```\ntest.test_future_stmt.test_future\ntest.test_inspect.test_inspect\ntest.test_pydoc.test_pydoc\ntest___all__\ntest__interpreters\ntest_builtin\ntest_capi\ntest_clinic\ntest_compileall\ntest_crossinterp\ntest_datetime\ntest_enum\ntest_generated_cases\ntest_idle\ntest_import\ntest_importlib\ntest_interpreters\ntest_json\ntest_lazy_import\ntest_struct\ntest_subprocess\ntest_symtable\ntest_tools\ntest_trace\ntest_traceback\ntest_tracemalloc\ntest_typing\ntest_unittest\ntest_xmlrpc\ntest_zipfile\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-149739\n* gh-151090\n* gh-151105\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2026-05-10T14:15:59Z","url":"https://github.com/python/cpython/issues/149640"}
| 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:483676dd-ca5f-ede9-3d3c-bd3df8a03ce8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DEB8:785A9:386FA41:47A6B31:6B01F253 |
| html-safe-nonce | 1821e59da4cf47ee70a6275f6bb84eccfeaf165ac7f3c04fd759a264428e390a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUI4Ojc4NUE5OjM4NkZBNDE6NDdBNkIzMTo2QjAxRjI1MyIsInZpc2l0b3JfaWQiOiI1NTk3MjQzNzAwMjU1MjU3MTcxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4db2905edf8458a85752aee0647a1bbab3ac3723e77f5d3713d4980b3e301ee7 |
| hovercard-subject-tag | issue:4415844469 |
| 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/149640/issue_layout |
| twitter:image | https://opengraph.githubassets.com/55f06e84d25a0426e275fc0c15fb9d6f3b01f0d5ced56e9cb54dac3f0a937d40/python/cpython/issues/149640 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/55f06e84d25a0426e275fc0c15fb9d6f3b01f0d5ced56e9cb54dac3f0a937d40/python/cpython/issues/149640 |
| og:image:alt | Bug report Bug description: Inspired by #149321 I decided to see how well the test suite works with PYTHON_LAZY_IMPORTS=all / -X lazy_imports=all, which makes all imports lazy. It's nowhere near as... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width