Skip to content

Registry

pikit.registry

A tiny name -> class registry with a decorator API.

Contributors add a new method by writing one file and decorating their class; no edits to core code are required. Attacks and defenses each get their own registry instance (see attacks/__init__.py and defenses/__init__.py).

Registry

Registry(kind: str)

Bases: Generic[T]

Maps a short string key to a class.

Examples

reg = Registry("attack") @reg.register("naive") ... class _Naive: # doctest: +SKIP ... ... reg.list() # doctest: +SKIP ['naive']

register

register(key: str) -> Callable[[Type[T]], Type[T]]

Class decorator that records cls under key.

The decorator also sets cls.name = key if the class did not define its own, so the instance carries a stable identifier.

get

get(key: str) -> Type[T]

Return the class registered under key.

Raises

KeyError If key is unknown, with the list of available keys.

list

list() -> List[str]

Return all registered keys, sorted.