Python int() accepts ' 42\n', '1_000' and Arabic-Indic digits but rejects '1.0': "ValueError: invalid literal for int() with base 10: '1.0'"
int(str) is lenient and strict in surprising places. It strips whitespace (int(' 42\n') is 42), accepts underscores (int('1_000') is 1000) and any Unicode decimal digits (int('٤٢') is 42), so it is a weak validator for IDs or user input. Yet int('1.0') raises ValueError: invalid literal for int() with base 10: '1.0', which breaks on values exported as floats from spreadsheets or JSON. Since 3.11, int('1' * 5000) raises ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has 5000 digits; use sys.set_int_max_str_digits() to increase the limit (str() of a huge int fails similarly). Fix: validate with a regex such as r'[0-9]+' (re.ASCII) before converting, use int(Decimal(s)) for decimal strings, and raise the digit limit explicitly only where needed. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.