[Python-bugs-list] [ python-Bugs-564601 ] patch 551410 broke xrange

noreply@sourceforge.net noreply@sourceforge.net
Tue, 04 Jun 2002 22:54:14 -0700


Bugs item #564601, was opened at 2002-06-04 16:31
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=564601&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 7
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Raymond Hettinger (rhettinger)
Summary: patch 551410 broke xrange

Initial Comment:
Patch 551410 is broken.

>>> a = iter(xrange(10))
>>> for i in a:
...     print i    
...     if i == 4: print '*', a.next()
... 
0
1
2
3
4
* 0
5
6
7
8
9
>>>

Compare to:

>>> a = iter(range(10))
>>> for i in a:
...     print i
...     if i == 4: print '*', a.next()
... 
0
1
2
3
4
* 5
6
7
8
9
>>> 


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

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-06-05 00:54

Message:
Logged In: YES 
user_id=80475

Added alternative patch with full-blown rangeiterobject just 
like listobject.c.  Given x=xrange(n), the patch assures that 
id(iter(iter(x))) == id(iter(x)) and assures that id(iter(x))!=id
(x) so that xrange() is identical in behavior to range() in all 
iteration aspects.

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-06-04 23:48

Message:
Logged In: YES 
user_id=80475

See attached patch.
Given x=xrange(n), the patch assures that id(iter(iter(x))) 
== id(iter(x)).

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

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