from typing import get_origin
from typing import Union
from typing import get_args


def is_optional_type(type_annotation) -> bool:
    """ Determines if a type is Optional[XXX]
    :param type_annotation: A type annotation, e.g Optional[float] or float
    :return: Whether the type annotation is an optional
    """
    if get_origin(type_annotation) is Union:
        args = get_args(type_annotation)
        return len(args) == 2 and type(None) in args  # pylint:disable=unidiomatic-typecheck
    return False