- F11 PopulateRule field_name/collection_name corrections - F12 service adaptor update handles PopulatingRepository - F13 nested-references section; F14 authless /users/me guidance - F15 template ruff-clean; F16 stop vendoring .ruff_cache, ship .gitignore - document --template-style in build_recipe/spec_first_routing; refresh collected openapi-first + standards bundle (12 modules, 43 components) - add trial.md and trial_findings.md (F1-F16, re-trial A/B evidence)
29 lines
876 B
Python
29 lines
876 B
Python
"""# Summary
|
|
|
|
Family registry — resolve a ``(kind, variant, mode)`` triple to a root class.
|
|
|
|
A single lookup replaces hand-rolled ``if/else`` family selection.
|
|
"""
|
|
|
|
# Populated by ``register`` as families import.
|
|
_FAMILIES: dict[str, dict[str, dict[str, type]]] = {}
|
|
|
|
|
|
def register(kind: str, variant: str, root_cls: type, mode: str = "default") -> type:
|
|
"""Register ``root_cls`` for a ``(kind, variant, mode)`` triple.
|
|
|
|
Returns:
|
|
Type: The registered class (so it can be used as a decorator).
|
|
"""
|
|
_FAMILIES.setdefault(kind, {}).setdefault(variant, {})[mode] = root_cls
|
|
return root_cls
|
|
|
|
|
|
def resolve_root(kind: str, variant: str, mode: str = "default") -> type:
|
|
"""Return the root class for a ``(kind, variant, mode)`` triple.
|
|
|
|
Raises:
|
|
KeyError: When no family matches the triple.
|
|
"""
|
|
return _FAMILIES[kind][variant][mode]
|