[Python-bugs-list] [ python-Bugs-730296 ] Unexpected Changes in list Iterator

SourceForge.net noreply@sourceforge.net
Wed, 30 Apr 2003 09:45:13 -0700


Bugs item #730296, was opened at 2003-04-30 09:45
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=730296&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Gary H. Loechelt (loechelt)
Assigned to: Nobody/Anonymous (nobody)
Summary: Unexpected Changes in list Iterator

Initial Comment:
I encountered an unexpected change in the behavior of
the iterator for the built-in list class.  I created a
subclass of the list class in which a start attribute
was added.  The intended behavior was to make the
list look shorter by "hiding" an arbitrary number of
starting elements.  The start attribute was used to
control the number of hidden elements.  In order to
make my shifted list class work in my application,
I had to override a number of special methods,
including the __iter__ method.  In Python 2.2.1 and
Python 2.3a2, the default __iter__ method indexed over
the entire, unshifted list even with other special
methods changed to reflect the shifting.  Therefore, I
had to override the __iter__ method as well.  When
I tested my application on Python 2.3b1, I encountered
an error which I tracked down to my __iter__
method.  I found that it had doubled the shift of the
starting value.  Eventually, I traced this to a change
in the behavior of the default __iter__ method of the
built-in list class.  I was able to recreate the
problem
with a simple test case.

I created a simple shifted list class with a public
start attribute, a __len__ method that subtracts start
from
the length of the list, and a __getitem__ method that
adds start to the index during element access.
Iteration over the list (using the default __iter__
inherited from list) returns all the elements in Python
2.2.1,
but only the elements after the start value in Python
2.3b1.  This change in behavior was an unexpected
surprise for me!


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

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