from typing import Union
from pathlib import Path
from typing import Dict
from typing import List
import json
import yaml
import warnings


def load_dict_from_file(file_path: Union[str, Path]) -> Union[Dict, List]:
    """ Loads a dict or a list from a .yaml or .json file """
    if isinstance(file_path, str):
        file_path = Path(file_path)

    if file_path.suffix in ['.json']:
        with file_path.open() as fp:
            return json.load(fp)
    elif file_path.suffix in ['.yaml', '.yml']:
        if yaml is None:
            warnings.warn("The yaml module is not installed, cannot load a yaml file !!", RuntimeWarning, stacklevel=2)
            return {}
        else:
            with file_path.open() as fp:
                return yaml.load(fp, Loader=yaml.FullLoader)
    else:
        raise ValueError(f"{file_path.suffix} is not a known dict-like file type")