Issue1560858

classification
Title: range(long,long) doesn't work
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: cgroves Nosy List: cgroves, leouserz, owenomalley
Priority: normal Keywords:

Created on 2006-09-18.16:14:26 by owenomalley, last changed 2007-07-30.04:09:58 by cgroves.

Messages
msg1230 (view) Author: Owen O\'Malley (owenomalley) Date: 2006-09-18.16:14:26
The following program fails in jython 2.2a1:

a = long(2)**32
range(a, a+1)

with:

TypeError: range(): 1st arg can't be coerced to int

cPython gets it right:

[4294967296L]
msg1231 (view) Author: Deleted User leouserz (leouserz) Date: 2006-12-20.18:34:50
a first cut at a patch by converting the ints in __builtin__.range(....)

to longs and replacing calls to py2int to py2long appears to solve the exception.  There is always the possibility of Overflow which will probably need to be investigated.

Oddly, xrange in python does not work with this value.  I wonder if this is a bug in xrange and should be implemented to work in jython?

leouser
msg1232 (view) Author: Deleted User leouserz (leouserz) Date: 2006-12-20.18:45:12
"Note: xrange() is intended to be simple and fast. Implementations may impose restrictions to achieve this. The C implementation of Python restricts all arguments to native C longs ("short" Python integers), and also requires that the number of elements fit in a native C long."

from:
http://docs.python.org/lib/built-in-funcs.html

seems, that there are limits so it seems reasonable that xrange is doing the right thing.

leouser
msg1233 (view) Author: Charlie Groves (cgroves) Date: 2007-07-30.04:09:58
Fixed in r3366 as Leo mentioned in his first comment.  This will still prevent stuff using range with a value greater than a Java long, but that's a bigger problem and we can let it wait until someone runs into it.
History
Date User Action Args
2006-09-18 16:14:26owenomalleycreate