INNER CODE UNIT · Python

positive_int

erikbern/ann-benchmarks · ann_benchmarks/main.py:28

def positive_int(input_str: str) -> int:
    """
    Validates if the input string can be converted to a positive integer.

    Args:
        input_str (str): The input string to validate and convert to a positive integer.

    Returns:
        int: The validated positive integer.

    Raises:
        argparse.ArgumentTypeError: If the input string cannot be converted to a positive integer.
    """
    try:
        i = int(input_str)
        if i < 1:
            raise ValueError
    except ValueError:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…