Coverage for astrocyte/mip/__init__.py: 91%

11 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-04 05:24 +0000

1"""Memory Intent Protocol (MIP) — declarative memory routing. 

2 

3See docs/_design/memory-intent-protocol.md for the design specification. 

4 

5:class:`MipRouter` and :func:`load_mip_config` are lazy-loaded via PEP 562 

6``__getattr__`` — ``astrocyte.types`` imports ``astrocyte.mip.schema`` at 

7module scope for :class:`RoutingDecision` fields, so eagerly importing 

8``router`` / ``loader`` here creates a circular import. 

9 

10Only names actually defined at module scope appear in ``__all__`` (CodeQL's 

11``py/undefined-export`` rule does not recognize ``__getattr__``-resolved 

12names, and statically the names are genuinely undefined). ``from 

13astrocyte.mip import MipRouter`` still works — Python's attribute lookup 

14falls through to ``__getattr__``. 

15""" 

16 

17from typing import Any 

18 

19from astrocyte.mip.schema import MipConfig 

20 

21__all__ = ["MipConfig"] # Lazy names: MipRouter, load_mip_config (see __getattr__) 

22 

23 

24def __getattr__(name: str) -> Any: 

25 if name == "MipRouter": 

26 from astrocyte.mip.router import MipRouter 

27 

28 return MipRouter 

29 if name == "load_mip_config": 

30 from astrocyte.mip.loader import load_mip_config 

31 

32 return load_mip_config 

33 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")