INNER CODE UNIT · Python
__getattr__
Priivacy-ai/spec-kitty · src/charter/__init__.py:132
def __getattr__(name: str) -> Any:
"""Lazily resolve ``charter.<name>`` against its owning submodule.
Caches the resolved value on this module's ``globals()`` so repeat
access after the first does not re-run the import/lookup.
"""
if name not in _LAZY_IMPORTS:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
module_path, attr = _LAZY_IMPORTS[name]
value = getattr(importlib.import_module(module_path), attr)
globals()[name] = value
return value
def __dir__() -> list[str]:
return sorted(set(globals()) | set(_LAZY_IMPORTS))