[Python-bugs-list] [ python-Bugs-555042 ] zip() may trigger MemoryError
noreply@sourceforge.net
noreply@sourceforge.net
Sun, 12 May 2002 00:03:38 -0700
Bugs item #555042, was opened at 2002-05-12 02:57
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=555042&group_id=5470
Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
>Assigned to: Tim Peters (tim_one)
Summary: zip() may trigger MemoryError
Initial Comment:
The recent optimization of zip() trips a MemoryError
when the only iterable defining len() is xrange
(sys.maxint).
This error may appear in real code because of reliance
on zip's ability to truncate to the shortest input
sequence and because xrange(sys.maxint) was an idiom
for counting elements with-in a zip. With the
introduction of enumerate(), the latter is less likely.
The following code works in Py2.2.1 but fails in 2.3a0
(the tree as of 5/12/2002):
Python 2.3a0 (#29, May 12 2002, 02:30:00) [MSC 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for
more information.
>>> def g():
... for i in range(6):
... yield i
...
>>> zip(g(), xrange(3))
[(0, 0), (1, 1), (2, 2)]
>>> zip(g(), xrange(9))
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5)]
>>> import sys
>>> zip(g(), xrange(sys.maxint))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
MemoryError
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2002-05-12 03:03
Message:
Logged In: YES
user_id=31435
Assigned to me.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=555042&group_id=5470