INNER CODE UNIT · Python

__getattr__

faridrashidi/cnsplots · src/cnsplots/__init__.py:193

def __getattr__(name: str):
    """Load a public attribute on first access."""
    try:
        module_name, attribute_name = _LAZY_IMPORTS[name]
    except KeyError:
        raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from None

    module = import_module(module_name)
    value = module if attribute_name is None else getattr(module, attribute_name)
    globals()[name] = value
    return value


def __dir__() -> list[str]:
    """Return eager and lazy module attributes."""
    return sorted(set(globals()) | set(__all__))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…