[ python-Bugs-1512504 ] builtin enumerate overflows

SourceForge.net noreply at sourceforge.net
Tue Jun 27 09:25:49 CEST 2006


Bugs item #1512504, was opened at 2006-06-26 08:50
Message generated for change (Comment added) made by hythloday
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1512504&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: James Harlow (hythloday)
Assigned to: Raymond Hettinger (rhettinger)
Summary: builtin enumerate overflows

Initial Comment:
The index that the builtin function enumerate() returns
is a mere integer and will wrap back to a negative
number when it overflows. This seems to be by design
(unless I'm misunderstanding the point of
PyInt_FromLong), but is sufficiently surprising that
I'd suggest it's a bug anyway. I've attached a test
case - it takes a while to execute, but the results are
so deeply exciting that it's worth doing just for fun!

----------------------------------------------------------------------

>Comment By: James Harlow (hythloday)
Date: 2006-06-27 07:25

Message:
Logged In: YES 
user_id=458963

Fair enough, I take your points both about the ease of
making a new generator. Is it possible to make the existing
one a bit less surprising, though, by having it raise an
exception when it wraps? I'm at a loss to think of any
algorithm that would work correctly when it wraps, so a new
exception wouldn't be a change in interface reeeeeeeeally. ;)

Failing that, is it possible to document it?

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2006-06-27 05:13

Message:
Logged In: YES 
user_id=80475

You're correct.  The behavior was by design, emphasizing 
speed and simplicity over a toy limiting case.  If some 
app actually requires enumeration of over 2**31 objects, 
it is trivial to write a generator that gives the desired 
flexibility.  Of course, on 64 bit machines, the limit is 
a bit higher ;-)

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2006-06-27 03:22

Message:
Logged In: YES 
user_id=33168

Raymond, any comments?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1512504&group_id=5470


More information about the Python-bugs-list mailing list