You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reloading a lazy module that has not yet been materailized should be no-op #139686
Reloading a not-yet materialized lazy module is not supported well. It makes sense for the reloading in this case to be no-op since when the actual loading happens e.g. by accessing an attribute, the new code will be loaded anyway. Currently, the reload tries to reload the module while its loaded is lazy in the first place.
There is no way to surface the behaviour with the public API. Nevertheless, the private API for _LazyModule should be compatible with importlib.reload. I sent a fix in this PR
GH-139857 broke* refleak buildbots -- tests fail when executed twice:
$ ./python -m test -v test_importlib test_importlib -m 'LazyLoaderTests'
[...]
======================================================================
ERROR: test_attr_unchanged (test.test_importlib.test_lazy.LazyLoaderTests.test_attr_unchanged)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/encukou/dev/cpython/Lib/test/test_importlib/test_lazy.py", line 105, in test_attr_unchanged
self.assertEqual(TestingImporter.mutated_name, module.__name__)
^^^^^^^^^^^^^^^
File "/home/encukou/dev/cpython/Lib/importlib/util.py", line 213, in __getattribute__
raise ValueError(f"module object for {original_name!r} "
"substituted in sys.modules during a lazy "
"load")
ValueError: module object for 'lazy_loader_test' substituted in sys.modules during a lazy load
similar errors for test_delete_eventual_attrand test_delete_preexisting_attr.
* [edit] The tests pass again when re-run, so buildbot status is “warn” rather that “fail”.
And now that PEP 810 has been accepted, I don't know how important it is to try again to get the functionality in or if it would be better on PyPI, maybe with #127036 .
Activity
ericvsmith commentedon Oct 8, 2025
Please show some example code. Show how it works, and what you expect the behavior to be.
QEDady commentedon Oct 9, 2025
There is no way to surface the behaviour with the public API. Nevertheless, the private API for
_LazyModuleshould be compatible withimportlib.reload. I sent a fix in this PRgh-139686: Make reloading a lazy module no-op (GH-139857)
GH-139686: Update versionchanged directive to 'next' in importlib (GH…
encukou commentedon Jan 8, 2026
GH-139857 broke* refleak buildbots -- tests fail when executed twice:
test_delete_eventual_attrand test_delete_preexisting_attr.* [edit] The tests pass again when re-run, so buildbot status is “warn” rather that “fail”.
brettcannon commentedon Jan 8, 2026
I'll revert the change today to fix the buildbots.
Revert "pythongh-139686: Make reloading a lazy module no-op (pythonGH…
brettcannon commentedon Jan 8, 2026
I have a revert PR out and set to auto-merge.
And now that PEP 810 has been accepted, I don't know how important it is to try again to get the functionality in or if it would be better on PyPI, maybe with #127036 .
GH-139686: Revert "gh-139686: Make reloading a lazy module no-op (GH-…
pythonGH-139686: Revert "pythongh-139686: Make reloading a lazy modul…
pythonGH-139686: Revert "pythongh-139686: Make reloading a lazy modul…