Registry
A registry that maps names to types.
Usage
Registry(strict=False)Use :py:func:register to add entries, or call :py:meth:Registry.get directly.
Parameters
strict: bool = False-
If True, raises :py:exc:
KeyErroron missing lookups.
Attributes
| Name | Description |
|---|---|
| names | List all registered names. |
names
List all registered names.
names: list
Methods
| Name | Description |
|---|---|
| add() | Add a type to the registry. |
| get() | Get a registered type by name. |
add()
Add a type to the registry.
Usage
add(
name,
cls,
)See also :py:func:register for the module-level helper.
Parameters
name: str-
The name to register under.
cls: type-
The type to register.
get()
Get a registered type by name.
Usage
get(name)Checks :py:attr:Registry.strict to decide behavior on missing keys. Raises :py:exc:KeyError if strict mode is enabled and the name is not found.
Parameters
name: str-
The registered name to look up.
Returns
type-
The registered type.
Raises
KeyError-
If the name is not registered and strict mode is on.