MacroLens / code /methods /__init__.py
itouchz's picture
Upload methods/ (18-method baseline panel implementations)
02412f8 verified
Raw
History Blame Contribute Delete
1.41 kB
"""Methods package — registry-driven re-exports.
Each family module's ``@register``-decorated classes self-register at import
time. Importing this package eagerly imports every family module so
``ALL_METHODS`` is fully populated and ``ml.methods.<ClassName>`` resolves
without a per-call lazy fallback.
"""
from __future__ import annotations
from ._registry import ALL_METHODS, get, list_methods, register
# Eagerly import every family module so every @register decorator fires.
# Order is alphabetical for determinism. Any ImportError here is a real
# bug — let it propagate (do not silence).
from . import ( # noqa: E402,F401
classical,
llm,
llm_finetune,
llm_ts_reason,
naive,
sequence,
tsfm,
)
def __getattr__(name: str):
"""Resolve ``methods.<ClassName>`` lookups via the registry.
The registry stores classes by their lowercase ``name`` attr; the public
re-export uses the class's actual Python name (e.g. ``Persistence``,
``LightGBMRegressor``). Search every registered class for a Python-name
match, then fall back to the lowercase registry id.
"""
for cls in ALL_METHODS.values():
if cls.__name__ == name:
return cls
if name in ALL_METHODS:
return ALL_METHODS[name]
raise AttributeError(f"module 'methods' has no attribute {name!r}")
__all__ = ["ALL_METHODS", "get", "list_methods", "register"]