import typing


def parse_number_string(obj: str) -> typing.Union[int, float]:
    """Parse a string as number. First tries to parse as `int`, then as `float`. Throws a ValueError
    if `obj` is not a string.

    Args:
        obj : the string to parse
    """
    if not isinstance(obj, str):
        raise ValueError()
    try:
        return int(obj)
    except ValueError:
        return float(obj)