[Patches] Long ints for getitem,setitem,slices
Guido van Rossum
guido@python.org
Tue, 15 Feb 2000 10:48:18 -0500
> This patch allows long integers for getitem, setitem, and slicing.
>
> I think it's not complete yet, though, because sequence[-5L : pow(2,700L) ]
> raises an OverflowError, and it should really treat a too-large
> longint the same as a too-large integer. How should I fix this in Python/ceval.c?
> Compare the long int to sys.maxint? Take the longint's value as a
> "long long" instead, and check if it's too big to fit into a "long"?
> Ignore the error if OverflowError was raised?
You can't ignore the error, because the OverflowError could mean that
the number is negative (and then it should be treated as -sys.maxint,
which gets treated the same as 0).
I personally think it's no big deal to raise the OverflowError.
If you really want to be strict, catch the OverflowError, and then
inspect the sign of the original long int to decide whether it should
mean sys.maxint or 0. (This saves time in the common case -- no
overflow.)
--Guido van Rossum (home page: http://www.python.org/~guido/)