fl4health.utils.config module

exception InvalidConfigError[source]

Bases: ValueError

check_config(config)[source]

Check if Configuration Dictionary is valid

Return type:

None

load_config(config_path)[source]

Load Configuration Dictionary

Return type:

dict[str, Any]

narrow_dict_type(dictionary, key, narrow_type_to)[source]

Checks if a key exists in dictionary and if so, verify it is of type narrow_type_to.

Parameters:
  • dictionary (dict[str, Any]) – A dictionary with string keys.

  • key (str) – The key to check dictionary for.

  • narrow_type_to (type[T]) – The expected type of dictionary[key]

Returns:

The type-checked value at dictionary[key]

Return type:

T

Raises:

ValueError – If dictionary[key] is not of type narrow_type_to or if the key is not present in dictionary.

narrow_dict_type_and_set_attribute(self, dictionary, dictionary_key, attribute_name, narrow_type_to, func=None)[source]

Checks a key exists in dictionary, verify its type and sets the corresponding attribute. Optionally, passes narrowed value to function prior to setting attribute. If key is not present in dictionary or dictionary[dictionary_key] has the wrong type, a ValueError is thrown.

Parameters:
  • self (object) – The object to set attribute to dictionary[dictionary_key].

  • dictionary (dict[str, Any]) – A dictionary with string keys.

  • dictionary_key (str) – The key to check dictionary for.

  • narrow_type_to (type[T]) – The expected type of dictionary[key].

Raises:

ValueError – If dictionary[key] is not of type narrow_type_to or if the key is not present in dictionary.

Return type:

None