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:
$ ./python -Xlazy_imports=none -m test
Exception ignored in the internal traceback machinery:
Traceback (most recent call last):
File "/home/peter/develop/cpython/Lib/traceback.py", line 15, in <module>import tokenize
File "/home/peter/develop/cpython/Lib/tokenize.py", line 38, in <module>
lazy import _colorize
File "/home/peter/develop/cpython/Lib/_colorize.py", line 6, in <module>from dataclasses import dataclass, field, Field
File "/home/peter/develop/cpython/Lib/dataclasses.py", line 5, in <module>import annotationlib
File "/home/peter/develop/cpython/Lib/annotationlib.py", line 3, in <module>import ast
File "/home/peter/develop/cpython/Lib/ast.py", line 24, in <module>
lazy from _colorize import can_colorize, get_theme
ImportError: cannot import name 'can_colorize' from partially initialized module '_colorize' (most likely due to a circular import) (/home/peter/develop/cpython/Lib/_colorize.py)
Traceback (most recent call last):
File "/home/peter/develop/cpython/Lib/runpy.py", line 201, in _run_module_as_mainreturn _run_code(code, main_globals, None,
File "/home/peter/develop/cpython/Lib/runpy.py", line 87, in _run_codeexec(code, run_globals)
File "/home/peter/develop/cpython/Lib/test/__main__.py", line 1, in <module>from test.libregrtest.main import main
File "/home/peter/develop/cpython/Lib/test/libregrtest/main.py", line 8, in <module>import trace
File "/home/peter/develop/cpython/Lib/trace.py", line 56, in <module>import tokenize
File "/home/peter/develop/cpython/Lib/tokenize.py", line 38, in <module>
lazy import _colorize
File "/home/peter/develop/cpython/Lib/_colorize.py", line 6, in <module>from dataclasses import dataclass, field, Field
File "/home/peter/develop/cpython/Lib/dataclasses.py", line 5, in <module>import annotationlib
File "/home/peter/develop/cpython/Lib/annotationlib.py", line 3, in <module>import ast
File "/home/peter/develop/cpython/Lib/ast.py", line 24, in <module>
lazy from _colorize import can_colorize, get_theme
ImportError: cannot import name 'can_colorize' from partially initialized module '_colorize' (most likely due to a circular import) (/home/peter/develop/cpython/Lib/_colorize.py)
The new REPL doesn't work:
$ ./python -X lazy_imports=none
Python 3.15.0a8+ (heads/pr_149318:6a88c2deeb3, May 3 2026, 10:35:20) [GCC 15.2.1 20260209] on linux
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Exception ignored in the internal traceback machinery:
Traceback (most recent call last):
File "/home/peter/develop/cpython/Lib/traceback.py", line 15, in <module>import tokenize
File "/home/peter/develop/cpython/Lib/tokenize.py", line 38, in <module>
lazy import _colorize
File "/home/peter/develop/cpython/Lib/_colorize.py", line 170, in <module>@dataclass(frozen=True, kw_only=True)
File "/home/peter/develop/cpython/Lib/dataclasses.py", line 1456, in wrapreturn _process_class(cls, init, repr, eq, order, unsafe_hash,
File "/home/peter/develop/cpython/Lib/dataclasses.py", line 1064, in _process_class
cls_annotations = annotationlib.get_annotations(
AttributeError: module 'annotationlib' has no attribute 'get_annotations'
Traceback (most recent call last):
File "/home/peter/develop/cpython/Lib/site.py", line 513, in register_readlineimport rlcompleter # noqa: F401
File "/home/peter/develop/cpython/Lib/rlcompleter.py", line 34, in <module>import inspect
File "/home/peter/develop/cpython/Lib/inspect.py", line 146, in <module>from annotationlib import Format, ForwardRef
File "/home/peter/develop/cpython/Lib/annotationlib.py", line 3, in <module>import ast
File "/home/peter/develop/cpython/Lib/ast.py", line 24, in <module>
lazy from _colorize import can_colorize, get_theme
File "/home/peter/develop/cpython/Lib/_colorize.py", line 170, in <module>@dataclass(frozen=True, kw_only=True)
File "/home/peter/develop/cpython/Lib/dataclasses.py", line 1456, in wrapreturn _process_class(cls, init, repr, eq, order, unsafe_hash,
File "/home/peter/develop/cpython/Lib/dataclasses.py", line 1064, in _process_class
cls_annotations = annotationlib.get_annotations(
AttributeError: module 'annotationlib' has no attribute 'get_annotations'warning: can't use pyrepl: module 'annotationlib' has no attribute 'get_annotations'
>>>
I compiled a list of all the standard library modules that currently don't work under -X lazy_imports=none:
mailboxloggingbdbpdbasttokenizeturtleensurepipinspectunittestpy_compiletabnannycodeasynciotracebackantigravitycontextlibdoctestpathlibpstatscompileallzipfilegetpasszipapppydocwebbrowserconfigparsersubprocessvenvrlcompleterpyclbrdifflibtraceannotationlibimaplibpickletoolsglob
I've already raised my concerns about this on DPO (in fact, LWN wrote an entire article 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.
Linked PRs
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:
The new REPL doesn't work:
I compiled a list of all the standard library modules that currently don't work under
-X lazy_imports=none:mailboxloggingbdbpdbasttokenizeturtleensurepipinspectunittestpy_compiletabnannycodeasynciotracebackantigravitycontextlibdoctestpathlibpstatscompileallzipfilegetpasszipapppydocwebbrowserconfigparsersubprocessvenvrlcompleterpyclbrdifflibtraceannotationlibimaplibpickletoolsglobI've already raised my concerns about this on DPO (in fact, LWN wrote an entire article 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.
Linked PRs