import inspect
from typing import Union
from typing import get_args


def get_annotation_class(parameter: inspect.Parameter) -> Union[type, None]:
    """
    Get the class of the annotation.
    # Parameters
        parameter: `inspect.Parameter`
            The parameter to get the class of.
    # Returns
    `Union[type, None]` The type or None.
    """
    # If the type is a `_GenericAlias`, we care what the arguments are inside.
    # Thus, we get the annotation args. If it is empty, it is not a
    # `_GenericAlias` and we can return the value.
    annotation_args = get_args(parameter.annotation)
    if not annotation_args:
        return parameter.annotation

    # If there are more than one argument, we return None because it is easier
    # to handle.
    if len(annotation_args) > 1:
        return None

    # Otherwise return the found type.
    return annotation_args[0]