def parseDigits(digits: str, base: int) -> int:
    """
    Wrapper around the "int" constructor that generates a slightly more
    detailed ValueError message if the given string contains characters that
    are not valid as digits in the given base.
    """
    try:
        return int(digits, base)
    except ValueError:
        baseDesc = {2: "binary", 10: "decimal", 16: "hexadecimal"}
        raise ValueError(f"bad {baseDesc[base]} number: {digits}") from None