Bug report
Bug
Accessing a lazily imported module via attribute access triggers the module's __getattr__, instead of resolving the lazy import.
Minimal Repro
# pkg/__init__.py
lazy from ._version import __version__
def __getattr__(name):
import importlib
return importlib.import_module(f"{__name__}.{name}")
>>> import pkg
>>> pkg.__version__
ModuleNotFoundError: No module named 'pkg.__version__'
How this Happened
The check in _Py_module_getattro_impl() (Objects/moduleobject.c) was the fix for
gh-144957, when lazy from put placeholders into the source module. gh-150052 removed
those placeholders, so now we override the lazy import reification with the __getattr__ check.
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug
Accessing a lazily imported module via attribute access triggers the module's
__getattr__, instead of resolving the lazy import.Minimal Repro
How this Happened
The check in
_Py_module_getattro_impl()(Objects/moduleobject.c) was the fix forgh-144957, when
lazy fromput placeholders into the source module. gh-150052 removedthose placeholders, so now we override the lazy import reification with the
__getattr__check.CPython versions tested on:
3.15
Operating systems tested on:
Linux
Linked PRs
__getattr__blocking reification of lazy imports #158825