from typing import Optional
import random
from typing import List


def extract_sample(word_list: list, sample_size: Optional[int] = None) -> list:
    """Returns a random sample from the word list or a shuffled copy of the word list.

    :param word_list: the list of words to extract the random sample from
    :param sample_size: If this number is greater than the length of the word list, then just return a shuffled
                        copy of the word list.
    """
    if not sample_size or len(word_list) <= sample_size:
        return random.sample(word_list, k=len(word_list))
    else:
        sample: List[str] = []
        while len(sample) < sample_size and len(word_list) > 0:
            sample += [word for word in random.sample(word_list, k=sample_size) if word not in sample]
            word_list = [word for word in word_list if word not in sample]
        if sample_size < len(sample):
            return random.sample(sample, k=sample_size)
        return sample