TheAlgorithms/Python · error · TypeError

Input value of [{number=}] must be an integer

Error message

Input value of [{number=}] must be an integer

What it means

Raised by is_proth_number(number) in maths/special_numbers/proth_number.py when the argument is not an int. The predicate factors out powers of 2 from number-1, which requires exact integer arithmetic, so floats like 6.0 (and strings, None, etc.) are rejected up front. Note the message uses the {number=} self-documenting f-string format, e.g. 'Input value of [number=6.0] must be an integer'.

Source

Thrown at maths/special_numbers/proth_number.py:89

    True
    >>> is_proth_number(4)
    False
    >>> is_proth_number(5)
    True
    >>> is_proth_number(34)
    False
    >>> is_proth_number(-1)
    Traceback (most recent call last):
        ...
    ValueError: Input value of [number=-1] must be > 0
    >>> is_proth_number(6.0)
    Traceback (most recent call last):
        ...
    TypeError: Input value of [number=6.0] must be an integer
    """
    if not isinstance(number, int):
        message = f"Input value of [{number=}] must be an integer"
        raise TypeError(message)

    if number <= 0:
        message = f"Input value of [{number=}] must be > 0"
        raise ValueError(message)

    if number == 1:
        return False

    number -= 1
    n = 0
    while number % 2 == 0:
        n += 1
        number //= 2
    return number < 2**n


if __name__ == "__main__":
    import doctest

View on GitHub (pinned to f5988cc097)

Solutions

  1. Coerce integral floats: is_proth_number(int(x)) when x.is_integer()
  2. Keep candidates in integer arithmetic end-to-end
  3. Add an isinstance(n, int) guard at your boundary with a domain-specific message

Example fix

// before
is_proth_number(6.0)  # TypeError

// after
is_proth_number(int(6.0))
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(n, int) or isinstance(n, bool):
    n = int(n)
print(is_proth_number(n))

Type guard

def is_builtin_int(v) -> TypeGuard[int]:
    return isinstance(v, int) and not isinstance(v, bool)

Try / catch

try:
    is_proth_number(n)
except TypeError:
    is_proth_number(int(n))

Prevention

When it happens

Trigger: Calling is_proth_number(6.0), is_proth_number('7'), or is_proth_number(None). The type check precedes the range check, so 0/-1 raise the ValueError instead.

Common situations: Float-typed candidates from divisions or JSON; numpy scalars; generic pipelines that forward unchecked values to math predicates.

Related errors


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/4a544dd4abd838a1. Report an issue: GitHub.