from typing import Union
from typing import Tuple
import re


def parse_lonlat(lonlat: Union[str, Tuple[str, str]]) -> Tuple[float, float]:
    """Return longitude and latitude from a string.

    Parameters
    ----------
    lonlat : Union[str, Tuple[str, str]]
      A tuple or a str of lon and lat coordinates.

    Returns
    -------
    Tuple[float, float]
    """
    try:
        if isinstance(lonlat, str):
            lon, lat = tuple(map(float, re.findall(r"[-+]?[0-9]*\.?[0-9]+", lonlat)))
        elif isinstance(lonlat, tuple):
            lon, lat = map(float, lonlat)
        else:
            raise ValueError
        return lon, lat
    except Exception as e:
        msg = "Failed to parse longitude, latitude coordinates {}".format(lonlat)
        raise Exception(msg) from e