"""Process-wide registry that generated modules register themselves into."""
from __future__ import annotations

from typing import Callable, Dict

_HANDLERS: Dict[str, Callable[..., object]] = {}


def register(key: str, fn: Callable[..., object]) -> None:
    if key in _HANDLERS:
        raise KeyError(f"duplicate registry key: {key}")
    _HANDLERS[key] = fn


def lookup(key: str) -> Callable[..., object]:
    return _HANDLERS[key]


def keys() -> list:
    return sorted(_HANDLERS)


def size() -> int:
    return len(_HANDLERS)
