registries
Generic EnumRegistry and DescriptorRegistry base classes for runtime-extensible registries.
EnumRegistry
Minimal registry helper for enum-like string values.
meta_consts.py exposes many register/is_known pairs. Centralizing the
semantics here keeps runtime-extensible enums consistent while still
allowing static enums for IDE help.
Source code in src/horde_model_reference/registries.py
__init__
Initialize the enum registry with an optional iterable of initial values.
Parameters:
-
initial(Iterable[T]) –An iterable of initial string values to populate the registry with.
Source code in src/horde_model_reference/registries.py
is_known
Check if a value is known (registered) in the enum registry.
Parameters:
Returns:
-
bool(bool) –True if the value is known (registered), False otherwise.
Source code in src/horde_model_reference/registries.py
register
Register a new value in the enum registry.
Attempting to register a value that is already known is a no-op.
Parameters:
Source code in src/horde_model_reference/registries.py
values
Get a set of all known (registered) values in the enum registry.
Returns:
mutable_values
Expose a live set for backwards-compatible global aliases.
Returns:
DescriptorRegistry
Registry for keyed descriptors with a rebuild hook for derived data.
Category/baseline registries need to invalidate and rebuild derived lookups after mutation, but only once initialization is complete. This helper centralizes that lifecycle so new registries get the same safety guards by default.
Source code in src/horde_model_reference/registries.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
__init__
Initialize the descriptor registry.
Parameters:
-
rebuild(Callable[[dict[K, V]], None]) –Function to call to rebuild derived data when the registry is updated.
Source code in src/horde_model_reference/registries.py
register
Register a key-value pair, raising if the key is already registered.
Parameters:
-
key(K) –The key to register.
-
value(V) –The value to associate with the key.
Raises:
-
ValueError–If the key is already registered.
Source code in src/horde_model_reference/registries.py
update_value
Update the value for an already registered key, raising if the key is not registered.
Parameters:
-
key(K) –The key to update.
-
value(V) –The new value to associate with the key.
Raises:
-
ValueError–If the key is not already registered.
Source code in src/horde_model_reference/registries.py
finalize
Mark initialization complete and trigger a final rebuild with all registered data.
Subsequent calls to register() will trigger immediate rebuilds, so this should only be called once after the initial batch of registrations is done.
Source code in src/horde_model_reference/registries.py
get
Get the value for a registered key, or raise if the key is unknown.
Parameters:
-
key(K) –The key to look up.
Returns:
-
V(V) –The value associated with the key.
Source code in src/horde_model_reference/registries.py
all
Get a copy of all registered key-value pairs.
Returns:
-
dict[K, V]–dict[K, V]: A copy of all registered key-value pairs.
contains
Check if a key is registered.
Parameters:
-
key(K) –The key to check.
Returns:
-
bool(bool) –True if the key is registered, False otherwise.