def split_optional_type(t):
    """Split optional from a type.

    E.g.:
        split_optional_type(Optional[int]) => True, int
        split_optional_type(int) => False, int
    """
    if isinstance(t, type):
        return False, t

    is_optional = hasattr(t, "__args__") and len(t.__args__) == 2 and t.__args__[-1] is type(None)
    if is_optional:
        return True, t.__args__[0]
    else:
        return False, t