i = -2147483648
OverflowError: integer literal too large
i = -2147483648L int(i) # it *is* a valid integer literal
As far as I traced back:
Python/compile.c::com_atom() calls Python/compile.c::parsenumber(s = "2147483648") calls Python/mystrtoul.c::PyOS_strtol() which
returns the ERANGE errno because it is given 2147483648 (which *is* out of range) rather than -2147483648.
My question: Why is the minus sign not considered part of the "atom", i.e. the integer literal? Should it be? PyOS_strtol() can properly parse this integer literal if it is given the whole number with the minus sign. Otherwise the special case largest negative number will always erroneously be considered out of range.
I don't know how the tokenizer works in Python. Was there a design decision to separate the integer literal and the leading sign? And was the effect on functions like PyOS_strtol() down the pipe missed?
-- Trent Mick email@example.com