Lightweight package initializer for ezpz.
The goal is to keep import ezpz fast and side-effect free while still
exposing the familiar helpers at the package level. Submodules are imported
on demand the first time one of their attributes is requested.
__getattr__(name)
Dynamically resolve attributes from submodules on first access.
Source code in src/ezpz/__init__.py
| def __getattr__(name: str) -> Any: # pragma: no cover - exercised via tests
"""Dynamically resolve attributes from submodules on first access."""
if name in _LAZY_MODULES:
module = _load_module(_LAZY_MODULES[name])
if module is None:
raise AttributeError(
f"Module {_LAZY_MODULES[name]!r} cannot be imported"
)
globals()[name] = module
return module
for module_name in _MODULE_SEARCH_ORDER:
module = _load_module(module_name)
if module is None:
continue
if hasattr(module, name):
value = getattr(module, name)
globals()[name] = value
return value
raise AttributeError(f"module 'ezpz' has no attribute {name!r}")
|