[Python-Dev] Cannot declare the largest integer literal.

Tim Peters tim_one@email.msn.com
Tue, 2 May 2000 22:20:20 -0400


[Trent Mick]
> >>> i = -2147483648
> OverflowError: integer literal too large
> >>> i = -2147483648L
> >>> int(i)   # it *is* a valid integer literal
> -2147483648

Python's grammar is such that negative integer literals don't exist; what
you actually have there is the unary minus operator applied to positive
integer literals; indeed,

>>> def f():
	return -42

>>> import dis
>>> dis.dis(f)
          0 SET_LINENO               1

          3 SET_LINENO               2
          6 LOAD_CONST               1 (42)
          9 UNARY_NEGATIVE
         10 RETURN_VALUE
         11 LOAD_CONST               0 (None)
         14 RETURN_VALUE
>>>

Note that, at runtime, the example loads +42, then negates it:  this wart
has deep roots!

> ...
> And was the effect on functions like PyOS_strtol() down the pipe
> missed?

More that it was considered an inconsequential endcase.  It's sure not worth
changing the grammar for <wink>.  I'd rather see Python erase the visible
distinction between ints and longs.