Coverage for src/bluetooth_sig/gatt/lazy_exports.py: 100%
12 statements
« prev ^ index » next coverage.py v7.14.3, created at 2026-06-28 01:26 +0000
« prev ^ index » next coverage.py v7.14.3, created at 2026-06-28 01:26 +0000
1"""PEP 562 lazy export helpers for GATT package barrels."""
3from __future__ import annotations
5import sys
6from importlib import import_module
9def lazy_getattr(package_name: str, export_map: dict[str, str], name: str) -> object:
10 """Resolve and cache a lazily exported name from *export_map*.
12 Args:
13 package_name: Fully qualified package name (for caching and errors).
14 export_map: Mapping of export name to fully qualified module path.
15 name: Attribute name requested via ``__getattr__``.
17 Returns:
18 The resolved export.
20 Raises:
21 AttributeError: If *name* is not in *export_map*.
22 """
23 module_path = export_map.get(name)
24 if module_path is None:
25 msg = f"module {package_name!r} has no attribute {name!r}"
26 raise AttributeError(msg)
27 module = import_module(module_path)
28 value = getattr(module, name)
29 setattr(sys.modules[package_name], name, value)
30 return value