Skip to content

graflo.architecture.evolution.state_core._shim

The module __getattr__ behind every deprecated state_core name.

Functions:

forwarder(module, targets)

A PEP 562 __getattr__ resolving each old name to its aspects home.

Parameters:

Name Type Description Default
module str

the deprecated module's __name__.

required
targets dict[str, tuple[str, str]]

old name -> (module under aspects, "" for the package itself; name there).

required
Source code in graflo/architecture/evolution/state_core/_shim.py
def forwarder(module: str, targets: dict[str, tuple[str, str]]) -> Callable[[str], Any]:
    """A PEP 562 ``__getattr__`` resolving each old name to its aspects home.

    Args:
        module: the deprecated module's ``__name__``.
        targets: old name -> (module under ``aspects``, "" for the package
            itself; name there).
    """

    def __getattr__(name: str) -> Any:
        if name not in targets:
            raise AttributeError(f"module {module!r} has no attribute {name!r}")
        where, new = targets[name]
        home = f"{_ASPECTS}.{where}" if where else _ASPECTS
        warn_deprecated(
            f"{module}.{name}",
            since="1.19.0",
            removed_in="2.0.0",
            use=f"{home}.{new}",
        )
        return getattr(importlib.import_module(home), new)

    return __getattr__