icclim._core.model.registry#

Contain the Registry class, a fancy enum replacement.

Module Contents#

class icclim._core.model.registry.Registry[source]#

Registry classes acts as fancy enums.

It allows to easily store and find constants of similar type. Registries are namespaces, so there is no need to instantiate it or any of its subclasses, every item is a class attribute.

Notes

Registries are not meant to store large collections, they are just fancy lookup tables for items with aliases and no case sensitivity.

classmethod lookup(query: T | str) T[source]#

Look up an item in the registry.

Parameters:

query (T or str) – The item to look up. It can be either an instance of the item class or a string.

Returns:

The found item.

Return type:

T

Raises:

InvalidIcclimArgumentError – If the item is not found in the registry.

Notes

This method performs a case-insensitive lookup. It first checks if the query is an instance of the item class, and if so, returns a deep copy of the query.

classmethod lookup_no_error(query: T | str) T | None[source]#

Also look up an item in the registry, but return None if not found.

Parameters:

query (T or str) – The item to look up. It can be either an instance of the item class or a string.

Returns:

The found item, or None if not found.

Return type:

T or None

classmethod every_aliases() list[T][source]#

Return a list of all aliases for items in the registry.

Returns:

A list of all aliases for items in the registry.

Return type:

list[T]

static get_item_aliases(item: T) list[str][source]#

Get the aliases for the given item.

Parameters:

item (T) – The item to get aliases for.

Returns:

A list of aliases for the item.

Return type:

list[str]

Notes

Should be overridden in subclasses.

classmethod catalog() dict[str, T][source]#

Return a dictionary of all items in the registry.

Returns:

A dictionary containing all items in the registry, where the keys are the item names and the values are the item instances.

Return type:

dict[str, T]

classmethod values() list[T][source]#

Return a list of all items in the registry.

Returns:

A list containing all items in the registry.

Return type:

list[T]