import builtins
from typing import Optional


def int(
    env_var: builtins.str,
    default: Optional[builtins.int] = None,
) -> Optional[builtins.int]:
    """
    Parse environment variable value into a integer.

    Args:
        env_var (str): Name of desired environment variable.
        default (int, optional): Optional fallback value.

    Returns:
        int (optional): Environment variable typecast into a integer.

    """
    try:
        return builtins.int(env_var)
    except ValueError:
        raise TypeError(
            f"Invalid integer value specified: {env_var} "
            "Parsenvy accepts only valid integers as integer values."
        )