Skip to content

core

Core components of the Stimulus library.

Modules:

  • registry

    A common basic registry object for all type of classes.

Classes:

BaseRegistry

Bases: AbstractRegistry

A generic registry implementation.

type is necessary to be registered as a metaclass.

registry-subclasses.

Source: https: // charlesreid1.github.io/python-patterns-the-registry.html

Methods:

  • all

    Return all the saved classes.

  • get

    Returns the saved classe with a given name as key.

  • register

    Function using a wrapper to register the given class with a specific name.

  • save_class

    Saves the class and the given name in the registry.

all classmethod

all() -> dict[str, Any]

Return all the saved classes.

Source code in src/stimulus/core/registry.py
79
80
81
82
@classmethod
def all(cls) -> dict[str, Any]:
    """Return all the saved classes."""
    return cls._REGISTRY

get classmethod

get(name: str) -> type[object] | None

Returns the saved classe with a given name as key.

Source code in src/stimulus/core/registry.py
74
75
76
77
@classmethod
def get(cls, name: str) -> type[object] | None:
    """Returns the saved classe with a given name as key."""
    return cls._REGISTRY.get(name.lower())

register classmethod

register(
    name: str | None = None,
) -> Callable[[type[object]], type[object]]

Function using a wrapper to register the given class with a specific name.

Source code in src/stimulus/core/registry.py
60
61
62
63
64
65
66
67
68
69
70
71
72
@classmethod
def register(  # type: ignore[override]
    cls,
    name: str | None = None,
) -> Callable[[type[object]], type[object]]:
    """Function using a wrapper to register the given class with a specific name."""

    def wrapper(wrapped_class: type[object]) -> type[object]:
        """Wrapper function to save a class to the registry."""
        cls.save_class(wrapped_class, name)
        return wrapped_class

    return wrapper

save_class classmethod

save_class(
    class_to_register: Any, name: str | None = None
) -> None

Saves the class and the given name in the registry.

Source code in src/stimulus/core/registry.py
49
50
51
52
53
54
55
56
57
58
@classmethod
def save_class(
    cls,
    class_to_register: Any,
    name: str | None = None,
) -> None:
    """Saves the class and the given name in the registry."""
    if name is None:
        name = class_to_register.__name__
    cls._REGISTRY[name.lower()] = class_to_register