from typing import Union
from pathlib import Path
from typing import List
from typing import Dict
import csv


def check_and_read_csv(path: Union[str, Path, List[Dict[str, str]]]) \
        -> List[Dict[str, str]]:
    """ If input is a file path, returns the data as a list of dicts (as returned by DictReader)
    Otherwise just returns the input

    :param path: Input file or its contents (as given by DictReader)
    :type path: Path, str or list[dict[str, str]]
    :return: File contents
    :rtype: list[dict[str, str]]
    """
    if not isinstance(path, list):
        if isinstance(path, str):
            path = Path(path)

        with path.open('r') as f:
            reader = csv.DictReader(f, dialect='unix')

            result = [row for row in reader]
    else:
        result = path

    return result