Message627

Author bgrus
Recipients
Date 2002-03-20.21:42:43
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
When using the iterator implementation from the CVS 
(which works very well btw.) I came along the 
following problem:

-- snip --
d = {1:2,3:4}
l = []
for i in iter(d): l.append(i)
-- snip --

throws "TypeError: iteration over non-sequence"

iter(d) creates a PyDictionaryIter; the for-Loop 
invokes __iter__() on that which hits 
PyObject.__iter__() and results in the TypeError.

I think the solution is pretty straigtforward:
a) __builtin__.iter(obj) checks whether obj is an 
iterator before calling obj.__iter__()
or
b) the iterator classes implement __iter__() 
returning themselves (or maybe a clone)

If it is in question whether the code above should 
work at all: It's an excerpt of test_descr.py from 
the Python 2.2 test suite.


History
Date User Action Args
2008-02-20 17:17:04adminlinkissue532747 messages
2008-02-20 17:17:04admincreate