Title: What is supposed to work under `-X lazy_imports=none`? · Issue #149321 · python/cpython · GitHub
Open Graph Title: What is supposed to work under `-X lazy_imports=none`? · Issue #149321 · python/cpython
X Title: What is supposed to work under `-X lazy_imports=none`? · Issue #149321 · python/cpython
Description: After seeing #149318, I was curious as to what the effect would be when run with -X lazy_imports=none. To my surprise, I noticed that very little seems to work under the setting already. For example, trying to run the test suite fails: $...
Open Graph Description: After seeing #149318, I was curious as to what the effect would be when run with -X lazy_imports=none. To my surprise, I noticed that very little seems to work under the setting already. For exampl...
X Description: After seeing #149318, I was curious as to what the effect would be when run with -X lazy_imports=none. To my surprise, I noticed that very little seems to work under the setting already. For exampl...
Opengraph URL: https://github.com/python/cpython/issues/149321
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"What is supposed to work under `-X lazy_imports=none`?","articleBody":"After seeing #149318, I was curious as to what the effect would be when run with `-X lazy_imports=none`. To my surprise, I noticed that very little seems to work under the setting already.\n\nFor example, trying to run the test suite fails:\n\n```pytb\n$ ./python -Xlazy_imports=none -m test\nException ignored in the internal traceback machinery:\nTraceback (most recent call last):\n File \"/home/peter/develop/cpython/Lib/traceback.py\", line 15, in \u003cmodule>\n import tokenize\n File \"/home/peter/develop/cpython/Lib/tokenize.py\", line 38, in \u003cmodule>\n lazy import _colorize\n File \"/home/peter/develop/cpython/Lib/_colorize.py\", line 6, in \u003cmodule>\n from dataclasses import dataclass, field, Field\n File \"/home/peter/develop/cpython/Lib/dataclasses.py\", line 5, in \u003cmodule>\n import annotationlib\n File \"/home/peter/develop/cpython/Lib/annotationlib.py\", line 3, in \u003cmodule>\n import ast\n File \"/home/peter/develop/cpython/Lib/ast.py\", line 24, in \u003cmodule>\n lazy from _colorize import can_colorize, get_theme\nImportError: cannot import name 'can_colorize' from partially initialized module '_colorize' (most likely due to a circular import) (/home/peter/develop/cpython/Lib/_colorize.py)\nTraceback (most recent call last):\n File \"/home/peter/develop/cpython/Lib/runpy.py\", line 201, in _run_module_as_main\n return _run_code(code, main_globals, None,\n File \"/home/peter/develop/cpython/Lib/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/home/peter/develop/cpython/Lib/test/__main__.py\", line 1, in \u003cmodule>\n from test.libregrtest.main import main\n File \"/home/peter/develop/cpython/Lib/test/libregrtest/main.py\", line 8, in \u003cmodule>\n import trace\n File \"/home/peter/develop/cpython/Lib/trace.py\", line 56, in \u003cmodule>\n import tokenize\n File \"/home/peter/develop/cpython/Lib/tokenize.py\", line 38, in \u003cmodule>\n lazy import _colorize\n File \"/home/peter/develop/cpython/Lib/_colorize.py\", line 6, in \u003cmodule>\n from dataclasses import dataclass, field, Field\n File \"/home/peter/develop/cpython/Lib/dataclasses.py\", line 5, in \u003cmodule>\n import annotationlib\n File \"/home/peter/develop/cpython/Lib/annotationlib.py\", line 3, in \u003cmodule>\n import ast\n File \"/home/peter/develop/cpython/Lib/ast.py\", line 24, in \u003cmodule>\n lazy from _colorize import can_colorize, get_theme\nImportError: cannot import name 'can_colorize' from partially initialized module '_colorize' (most likely due to a circular import) (/home/peter/develop/cpython/Lib/_colorize.py)\n```\n\nThe new REPL doesn't work:\n\n```pytb\n$ ./python -X lazy_imports=none\nPython 3.15.0a8+ (heads/pr_149318:6a88c2deeb3, May 3 2026, 10:35:20) [GCC 15.2.1 20260209] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\nFailed calling sys.__interactivehook__\nException ignored in the internal traceback machinery:\nTraceback (most recent call last):\n File \"/home/peter/develop/cpython/Lib/traceback.py\", line 15, in \u003cmodule>\n import tokenize\n File \"/home/peter/develop/cpython/Lib/tokenize.py\", line 38, in \u003cmodule>\n lazy import _colorize\n File \"/home/peter/develop/cpython/Lib/_colorize.py\", line 170, in \u003cmodule>\n @dataclass(frozen=True, kw_only=True)\n File \"/home/peter/develop/cpython/Lib/dataclasses.py\", line 1456, in wrap\n return _process_class(cls, init, repr, eq, order, unsafe_hash,\n File \"/home/peter/develop/cpython/Lib/dataclasses.py\", line 1064, in _process_class\n cls_annotations = annotationlib.get_annotations(\nAttributeError: module 'annotationlib' has no attribute 'get_annotations'\nTraceback (most recent call last):\n File \"/home/peter/develop/cpython/Lib/site.py\", line 513, in register_readline\n import rlcompleter # noqa: F401\n File \"/home/peter/develop/cpython/Lib/rlcompleter.py\", line 34, in \u003cmodule>\n import inspect\n File \"/home/peter/develop/cpython/Lib/inspect.py\", line 146, in \u003cmodule>\n from annotationlib import Format, ForwardRef\n File \"/home/peter/develop/cpython/Lib/annotationlib.py\", line 3, in \u003cmodule>\n import ast\n File \"/home/peter/develop/cpython/Lib/ast.py\", line 24, in \u003cmodule>\n lazy from _colorize import can_colorize, get_theme\n File \"/home/peter/develop/cpython/Lib/_colorize.py\", line 170, in \u003cmodule>\n @dataclass(frozen=True, kw_only=True)\n File \"/home/peter/develop/cpython/Lib/dataclasses.py\", line 1456, in wrap\n return _process_class(cls, init, repr, eq, order, unsafe_hash,\n File \"/home/peter/develop/cpython/Lib/dataclasses.py\", line 1064, in _process_class\n cls_annotations = annotationlib.get_annotations(\nAttributeError: module 'annotationlib' has no attribute 'get_annotations'\nwarning: can't use pyrepl: module 'annotationlib' has no attribute 'get_annotations'\n>>> \n```\n\nI compiled a list of all the standard library modules that currently don't work under `-X lazy_imports=none`:\n\n1. `mailbox`\n2. `logging`\n3. `bdb`\n4. `pdb`\n5. `ast`\n6. `tokenize`\n7. `turtle`\n8. `ensurepip`\n9. `inspect`\n10. `unittest`\n11. `py_compile`\n12. `tabnanny`\n13. `code`\n14. `asyncio`\n15. `traceback`\n16. `antigravity`\n17. `contextlib`\n18. `doctest`\n19. `pathlib`\n20. `pstats`\n21. `compileall`\n22. `zipfile`\n23. `getpass`\n24. `zipapp`\n25. `pydoc`\n26. `webbrowser`\n27. `configparser`\n28. `subprocess`\n29. `venv`\n30. `rlcompleter`\n31. `pyclbr`\n32. `difflib`\n33. `trace`\n34. `annotationlib`\n35. `imaplib`\n36. `pickletools`\n37. `glob`\n\nI've already raised my [concerns](https://discuss.python.org/t/concerns-about-x-lazy-imports-none/106203) about this on DPO (in fact, LWN wrote [an entire article](https://lwn.net/Articles/1061112/) about this), but anyway, what do we do? Do we consider this a bug? If so, how do we test for it? If not, then what is supposed to work? We should document the restrictions and expected behavior for disabling lazy imports.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-149338\n* gh-149389\n* gh-150129\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/ZeroIntensity","@type":"Person","name":"ZeroIntensity"},"datePublished":"2026-05-03T14:59:06Z","url":"https://github.com/python/cpython/issues/149321"}
| 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:ec5bad3b-ef59-42f4-7b7c-146a1c76aed2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C672:B53AF:340DC11:454C498:6B01FB80 |
| html-safe-nonce | 623d2857988feca308be0b4e864c6837c690367e13e75b1012e33a15c17c3714 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjcyOkI1M0FGOjM0MERDMTE6NDU0QzQ5ODo2QjAxRkI4MCIsInZpc2l0b3JfaWQiOiIxOTI1MDQwNTgwNTAxNTY4Mzg1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | cb74b63769f789ff8829d160093fd0450c8dd659c0d8fd080e5540688fcd18e2 |
| hovercard-subject-tag | issue:4372123246 |
| 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/149321/issue_layout |
| twitter:image | https://opengraph.githubassets.com/08f023cbe2d057d5e1196e385ede9e4d2bc04b769372b71b7897178f7c0a4500/python/cpython/issues/149321 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/08f023cbe2d057d5e1196e385ede9e4d2bc04b769372b71b7897178f7c0a4500/python/cpython/issues/149321 |
| og:image:alt | After seeing #149318, I was curious as to what the effect would be when run with -X lazy_imports=none. To my surprise, I noticed that very little seems to work under the setting already. For exampl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ZeroIntensity |
| 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