from typing import Union
import pathlib
from typing import Callable
from typing import Any
import yaml


def load_settings(yaml_path: Union[pathlib.Path, str], class_factory: Callable) -> Any:  # pragma: no cover
    """A generic method to load settings.

    Args:
        yaml_path: location of the YAML configuration file
        class_factory: a function generating pydantic objects storing configuration

    Returns:
        an object of type returned by class factory
    """
    with open(yaml_path) as file_handler:
        data_dict: dict = yaml.safe_load(file_handler)
        return class_factory(**data_dict)